python (65.1k questions)
javascript (44.2k questions)
reactjs (22.7k questions)
java (20.8k questions)
c# (17.4k questions)
html (16.3k questions)
r (13.7k questions)
android (12.9k questions)
How do I access data from useReducer(react) in other react-components?
How do I access the basket in other components like Navbar to show the contents of cart ?
And please correct me if there is any logical errors in the code.
Thanks in advance.
const cartReducer = (...
Siva
Votes: 0
Answers: 1
conditionally update state in useReducer
I have written a reducer.
export const reducer = (state, { type, payload }) => {
switch (type) {
case ACTION_TYPES.UPDATE_STATE:
return updateData({ state, payload });
default:
...
Aditi Sharma
Votes: 0
Answers: 0
Getting an error titled "Uncaught TypeError: Cannot read properties of undefined (reading 'cartFoodItems')" when clicking on my cart button
I am working on a food app that adds items to a cart then calculates the total amount. I am trying to implement a reducer as opposed to having multiple instances of state hooks and I am running into t...
mattangel
Votes: 0
Answers: 0
React - useReducer with asynchronous CRUD operations
I am trying to figure out how to use useReducer with asynchronous CRUD operations (using the fetch API).
In my mind the reducer function would look like this:
async function reducer(action, state) {
...
Laurent Dhont
Votes: 0
Answers: 1