Pass id to a React Component without params

Viewed 62

So I know there's a way to pass an id to another component via params with the useParams() hook. The thing is I don't want to show my user's ids on the URL. So my way of doing it is via Link. I put a Button and wrap it with a Link component. There I pass a pathname and in the state I pass the user data. Like this:

      <tbody>
        {persons.map((person, idx) => {
          return (
            <tr key={idx}>
              <td>{person.id}</td>
              <td>{person.name}</td>
              <td>{person.last_name}</td>
              <td>{person.age}</td>
              <td>{person.phone}</td>
              <td>{person.occupation}</td>
              <td>
                <Link to={{ pathname: "/path", state: person }}>
                  <Button> Edit </Button>
                </Link>
              </td>
            </tr>
          );
        })}
      </tbody>

So my question is: Is it right to do it this way? If not. Is there another way?

0 Answers
Related