0

I am trying to pass a function from a parent view to a child view

In Parent

const getStartedPressed = () => {
    console.log("Pressed")
  }

  return (
 <ApplicationProvider {...eva} theme={eva.light}>
          <WelcomeSliderScreen getStartedPressede={getStartedPressed} ></WelcomeSliderScreen>
        </ApplicationProvider>

and in Child

  const onGetStartedPressed = (): void => {
    useEffect(() => {
      // console.log('postArray',props.postArray.title)
      console.log('postObject',props?.postObject?.getStartedPressed) // optional-chaining would take care of the undefined check 
  
  },[props?.postObject?.title]) 
  }

 <Button
          style={styles.signUpButton}
          appearance="ghost"
          status="control"
          onPress={onGetStartedPressed}
        >
          Get Started
        </Button>

I am getting an error

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function
user567
  • 3,712
  • 9
  • 47
  • 80
  • 1
    Pass props like this: `` in child `const { yourFunction } = yourPorpsToChild` Dont forget to `const YourChildComponent = (yourPorpsToChild) => { ` ... and so on Take a look here in components>LoginScreen.js line 36 i pass `set setShowModal` to the file Components>ModalSignUp.js https://snack.expo.dev/@g1sm0/sign-up-screen-component-react-native-base – Gismo1337 Feb 25 '22 at 18:08
  • I did it this way but props.getStartedPressed in undefined const onGetStartedPressed = (props) => { return ( console.log(props.getStartedPressed) ) } – user567 Feb 25 '22 at 18:12
  • i edited my awnser above with a example. you dont catch the props in child. – Gismo1337 Feb 25 '22 at 18:13
  • thanks, it worked with your example – user567 Feb 25 '22 at 18:51
  • Does this answer your question? [How to pass props to {this.props.children}](https://stackoverflow.com/questions/32370994/how-to-pass-props-to-this-props-children) – Gismo1337 Feb 25 '22 at 21:12
  • I would be happy if you show your gratitude with an arrow pointing up. I am very new here and need this fame for my self-confidence. nah, maybe for new features on stackoverflow too. – Gismo1337 Feb 25 '22 at 21:13

0 Answers0