Last active
September 2, 2023 14:27
-
-
Save yurkimus/de9e465adaf45fa907dd1d1b9759b6fc to your computer and use it in GitHub Desktop.
Reactive URLSearchParams with ramda and react-router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [searchParams, setSearchParams] = useSearchParams({ [searchParam]: defaultValue, }) | |
useEffect(() => { | |
setSearchParams( | |
tap( | |
when( | |
compose(anyPass([isEmpty, isNil]), invokeGet(tabSearchParam)), | |
invokeSet(searchParam, defaultValue) | |
) | |
) | |
) | |
}, [searchParams]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const searchParam = 'test' | |
const defaultValue = 'value' | |
const invokeGet = invoker(1, 'get') | |
const invokeSet = invoker(2, 'set') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment