DEV Community

jyotirmoydeb1782
jyotirmoydeb1782

Posted on

How pass path value from child to Parent

Hello Everyone,

I am making a MERN crud app where I want to pass the _id of the record from my displayRecord.js component to app.js( inside the Route path = {} ) to update my data onclick on update button

Part of the code sort of goes like this

        ` 
          <td>
            <li>
              <Link to={`/${record._id}`}>
              <button className='updateRecordBtn' onClick={()=>updateRecord(record._id)}>UPDATE</button>
              </Link>
            </li>
          </td>
Enter fullscreen mode Exit fullscreen mode

`

I need to capture that and pass it to the path as follows

<Router>
        <Routes>
          <Route path={`/${record._id}`} element={<UpdateRecord />} />
          <Route path='/' element={<Home/>} />
        </Routes>
      </Router>
Enter fullscreen mode Exit fullscreen mode

How to make that {record._id} available in app.js. it is currently showing not available

Suggestions and possible solutions are appreciated

Top comments (0)