expo-router pass params to a typescript class-defined page

555 views Asked by At

I pass some parameters to the screen using expo-routing but the screen is a class-defined component, how can I get params? When I log props I have this: {"segment": "home/index"}

screen #1

router.replace({ pathname: 'home', params: { id: '123' } });

screen #2

export default class HomePage extends React.Component<HomePagePropsType, HomePageStateType> {

    constructor( props: HomePagePropsType ) {
        super( props );
        console.log( this.props )
    }

1

There are 1 answers

0
dalva On

This is because you need to use useLocalSearchParams from expo-router

Try this instead:

import { useLocalSearchParams } from 'expo-router'

const { id } = useLocalSearchParams();