A weird misuse of React’s context I just found: 1


A weird misuse of React’s context I just found:

1. The user clicks a record on a list page.
2. The record’s detail is fetched, then stored in context.
3. The detail page reads from context and displays the details.

Don’t do this…

1/2
Instead:
1. When the user clicks on a record, use an anchor that contains the record’s id
2. Read the record’s id from the anchor on the detail page
3. Fetch the record’s detail on the detail page

This isn’t just simpler - It also supports deep links to a specific detail page.
The real mistake here is forgetting about the URL.

I use the URL to store state when:

✅ I need to pass state from one page to another
✅ I want users to be able share a deep link
✅ I want users to be able to bookmark the page

View original on X