FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
React: avoid setDefaultHook, use getParams
NewsWeb Development

React: avoid setDefaultHook, use getParams

via Dev.to ReactDomantas Jurkus16h ago

A colleague of mine helped identify a pattern that has turned out to be a bit of a footgun. The goal was: when a customer opens mysite.com/?urlParam=foo , I want to load the correct FooComponent. However, if mysite.com is opened with no param is set, I want it to default to FooComponent as well. In the following component, a hook is used to set some sort of default parameter: export const MyAdvancedComponent = () => { useSetDefaultParameters (); const { params } = usePlaygroundContext (); return ( < div className = "..." > { params . foo === " foo " && < FooComponent /> } { params . foo === " bar " && < BarComponent /> } .... The hook itself monitors the url params for changes and updates a context whenever urlParam changes. export const useSetDefaultParameters = () => { const urlParam = useGetUrlParam (); const { setParam } = useMyContext (); useEffect (() => { const defaultValue = defaults [ urlParam ]; setParam ( urlParam , defaultValue ); }, [ urlParam ]); };

Continue reading on Dev.to React

Opens in a new tab

Read Full Article
2 views

Related Articles

Sony WF-1000XM6 Review: My New Favorite Earbuds
News

Sony WF-1000XM6 Review: My New Favorite Earbuds

Wired • 16h ago

What are you doing this weekend?
News

What are you doing this weekend?

Lobsters • 16h ago

News

Code in Your Mother Tongue: What is BhashaX ?

Medium Programming • 16h ago

My Moccamaster Delivers Drip Coffee Perfection
News

My Moccamaster Delivers Drip Coffee Perfection

Wired • 17h ago

Well Being in Times of Algorithms
News

Well Being in Times of Algorithms

Lobsters • 17h ago

Discover More Articles