简体   繁体   中英

Pass data from CLASS component to FUNCTIONNAL component REACT

I want to pass some data but cant access it in my functional component.

Once user submit a login on my Class component:

return (
  <Redirect
    to={{
      pathname: '/home',
      userName: this.state.name,
      state: { userName: this.state.name },
    }}
    userName={this.state.name}
  />
);

I want to get the userName data in a functional component but can't access it, I tried this.props etc (but its not a class) and all props, location, history etc return undefined .

Ok i didn't used it correctly before.. such time wasted but learning everyday, huge thanks @Brian Thompson for the answer i link the doc he gave: Functional components

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM