Search code examples
reactjsroutesstatereact-router-domreact-props

How can I transfer Props from one component to another via Link


My Code

The code shows that when you enter data in three lines, they must be transmitted via Link using the State method, but when you try to display them on the secStr page, it gives Undefined


Solution

  • You have to add the withRouter HOC (high order component) into secStr page to have access to location props and the state data

    Take a look at this:

    https://reactrouter.com/web/api/withRouter

    Something like this:

    import React, {
      Component
    } from "react";
    import {
      withRouter
    } from "react-router";
    
    class secStr extends Component {
      render() {
        console.log(this.props);
        return ( <
          div >
          date in inputs <
          br / >
          <
          /div>
        );
      }
    }
    export default withRouter(secStr);