How to update location.state with useLocation - idea is to use it instead of Redux, like common component? #2745
Unanswered
Maksss2018
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Which Remix packages are impacted?
remix
(Remix core)create-remix
@remix-run/architect
@remix-run/cloudflare-workers
@remix-run/dev
@remix-run/express
@remix-run/netlify
@remix-run/node
@remix-run/react
@remix-run/serve
@remix-run/server-runtime
@remix-run/vercel
What version of Remix are you using?
latest
What version of Node are you using? Minimum supported version is 14.
14
Steps to Reproduce
Well:
let location = useLocation()
or
let { location, state } = useHistory()
then
location.replace("/some/parent",{...state, newCommonStateParam: new Map()});
but we got an error like: state is null or something.
Expected Behavior
In ordinary SPA or PWA based on ReactJS we can easy attach useLocation and useHistory from react-router-dom to our components and interact with location state to share some small data between different components by avoiding complication of App common state (Redux or MobX) .... it is handy when app is SSR or like in this case we don't got an Redux (and actually we don't need it) but we need to update parent component with some data like name of selected header or something.
And .... yes ... I know that to create common context is also the way. But what for if there is an location.state and it is null.
Actual Behavior
location.state is read only ... and if we will use window.location like direct link to location.state then code validator returns error - for obvious reasons.
Beta Was this translation helpful? Give feedback.
All reactions