Redirect to another component by passing ID via table button in React

Asked

Viewed 196 times

0

I have a process component that should redirect me to another component, this other component will need to receive the process.ID, in order to render the records referring to the process.

I created such a method, but it was wrong, saying that this method does not exist in this context, as I could do it ?

I was recommended to see stateless and statefull, but I couldn’t apply it properly.

verProcesso(etapa) {
     window.location.href(`../processos/etapas.jsx?${etapa}`);
 }

How I rewrite the table

renderRows() {
 return this.state.list.map(processo=> {
  return (
   <tr key={processo.id}>
     <td>{processo.cliente}</td>
     <td>{processo.etapa}</td>
     <td>
       <button className="btn btn-sm btn-info ml-2"
          onClick={() => this.verProcesso(processo)}>
          <i className="fa fa-eye"></i>
       </button>
       </td>
   </tr>
  )
 })
}
  • 1

    my beautiful, good morning, have to apply "Arrow Function" to keep the context of "this" in reactjs

  • const verProcesses = step => { window.location.href(../processos/etapas.jsx?${etapa}); }

  • I put it this way but it is accusing error in the syntax const verProcesso = step => { window.location.href(../processos/etapas.jsx?${etapa}); }

  • It seems that it is missing, a Routes component for your React application and also not using window.location.href is not how it is done, even sending jsx address at the end does not exist this in React ... you’re learning?

  • I am learning I use routes, I have a file Routes.jsx that has a switch and a route for each link , but this serves only for the menu

  • @Virgilionovic I also tried to call a import { useHistory } from 'React-router-dom'; routeChange=()=> { Let path = ./home/home; Let history = useHistory(); history.push(path); }

  • @Virgilionovic there in my TD button I put onClick={() => this.routeChange()}> what I’m trying to do and very simple is u mbotão that redirects to another page passing the state , as if it were in php You can open a page by passing the parameters

  • There’s no such thing Andrews, in his current code of the expensive question ???

  • and that since I posted I’ve changed, I’m just trying to see some way

  • @Virgilionovic in all the examples I saw, the pages were the same never changed page

  • if you do not know what you are doing and so your doubt is already other

  • I know what I want but am problem to get the result I want, so I opened the question to get help on how to do it properly

Show 7 more comments
No answers

Browser other questions tagged

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