#I need a reducer example
9 messages · Page 1 of 1 (latest)
use signals cannot be used like reducer in general. Is there a method or example of managing all states from somewhere?
So far I've not needed that. Can you give an example of what you would normally do?
FOR EXAMPLE, there will be a form input somewhere on my site, you will enter your phone number and it will direct you to the main form page, but when you redirect, I want to send the phone number you entered there to the page we redirected. In short, the simple reducer logic in React is to control all the states from one place, not by always passing props.
I think you are looking towards managing the state from a single source, Try with context API
https://qwik.builder.io/docs/components/context
Even though I made the same code in the example, I get these errors.
Code(20): Calling a 'use*()' method outside 'component$(() => { HERE })' is not allowed. 'use*()' methods provide hooks to the 'component$' state and lifecycle, ie 'use' hooks can only be called synchronously within the 'component$' function or another 'use' method.
Error: Code(20): Calling a 'use*()' method outside 'component$(() => { HERE })' is not allowed. 'use*()' methods provide hooks to the 'component$' state and lifecycle, ie 'use' hooks can only be called synchronously within the 'component$' function or another 'use' method.
Uncaught Error: Code(20): Calling a 'use*()' method outside 'component$(() => { HERE })' is not allowed. 'use*()' methods provide hooks to the 'component$' state and lifecycle, ie 'use' hooks can only be called synchronously within the 'component$' function or another 'use' method.
Code(13): Actual value for useContext(docs.theme-context) can not be found, make sure some ancestor component has set a value using useContextProvider(). In the browser make sure that the context was used during SSR so its state was serialized. docs.theme-context Error: Code(13): Actual value for useContext(docs.theme-context) can not be found, make sure some ancestor component has set a value using useContextProvider(). In the browser make sure that the context was used during SSR so its state was serialized.
Code(13): Actual value for useContext(docs.theme-context) can not be found, make sure some ancestor component has set a value using useContextProvider(). In the browser make sure that the context was used during SSR so its state was serialized. Error: Code(13): Actual value for useContext(docs.theme-context) can not be found, make sure some ancestor component has set a value using useContextProvider(). In the browser make sure that the context was used during SSR so its state was serialized.
And this is with context being used in the layout?
error 20 means that you are calling a function called use* inside not-a-component$.
error 13 means that you're calling useContext(theId) in a component that doesn't have some parent calling useContextProvider(theId) for it
error 20 means that you are calling a function called use* inside not-a-component$.
this error is not true I used inside component$.
I dont understand error 13