Anti-pattern: Needlessly reading the URL


Anti-pattern: Needlessly reading the URL.

Example: A button that reads the URL to determine what it should do. 👎

Simpler solution: Pass a prop to the button to specify behavior. Then the button doesn’t need to contain URL logic. 👍

Sometimes the simplest solution is a prop.

Benefits of accepting a prop:

✅Avoids tightly coupling the component’s behavior to the URL, so the component is more flexible.

✅Avoids continuously having to update the button as new scenarios come up.

✅Easier to understand.

✅Easier to unit test.

View original on X