React-navigation v2 how to send Component by params

Asked

Viewed 79 times

0

I’m trying to send a Component to a new route via params, but the way I’m doing it doesn’t work. Can anyone point out my mistake?

Component A

this.props.navigation.navigate('ModalInput', {
          input: {
            component: <Input />,
          }
        });

Component Modalinput

    ...
render() {
    const params = this.props.navigation.state.params;

return (
<View>
params.input.component.children()
...
  • What is the error you are indicating?

  • using Children() as a function, it indicates that the function does not exist, if I try as attribute does not return anything

1 answer

1

I believe what you need is:

Component A

this.props.navigation.navigate('ModalInput', {
    itemId: <Input />,
});

Modalinput

const params = this.props;
const item = params.getParam('itemId', 'NO-ID'); /* itemId sendo o nome do parametro e NO-ID o valor padrão */

source: https://reactnavigation.org/docs/en/params.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.