score:1
You probably try to render somewhere the counter? Your default case returns the entire object, instead of just state.counter
.
Try it like this:
const counterReducer = (state = initialState, action) => {
switch(action.type){
case "INCREMENT":
{
return {
...state,
counter: state.counter + action.payLoad
}
}
case "DECREMENT":
return {
...state,
counter: state.counter - action.payLoad
}
default:
{
return state.counter;
}
}
}
Or in the component where you render it access the object property state.counter
score:1
There's nothing wrong with the reducer you've written.
Without the corresponding component code and based on the error you're seeing, it seems that you're using the entire state object ({ counter: 0, num: 0 }
, for example) within the React component that's using the state from this reducer.
Replacing the object ({ counter: 0, num: 0 }
, from the above example) with just the counter value (obj.counter
) should get it working
Source: stackoverflow.com
Related Query
- React error saying Objects are not valid as react child
- Objects are not valid as a React child getting error when adding div?
- Handling error in React with Formik: Objects are not valid as a React child
- Error Objects are not valid as a React child (found: Invalid date)
- Objects are not valid as a React child error when giving value to react-select
- React setState error -> Objects are not valid as a React child
- React Objects are not valid as a React child error
- Objects are not valid as a React child Error in next js
- Error in map function / Objects are not valid as a React child / React.js
- react map returned error of Objects are not valid as a React child
- Objects are not valid as a React child error in React Datatable
- Objects are not valid as a React child - Confusing Error
- Getting Error Like Objects are not valid as a React child In ReactJs
- React Axios fetch response with error Objects are not valid as a React child
- I AM HAVING ERROR WHEN TRYING TO MAP A DATA IN REACT . Objects are not valid as a React child (found: object with keys {children}), How do i solve it?
- What is causing this error - Objects are not valid as a React child (found: object with keys {id, task})
- Getting error Objects are not valid as a React child
- Objects are not valid as a React child with state while rendering error
- REact error Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead
- Getting a Objects are not valid as a React child error even though I am not trying to render an object
- Trying to add an array of objects using react useState but getting the error 'Objects are not valid as a React child (found: object with keys {})'
- Handling error Objects are not valid as a React child
- Passing an array of object to useState throws this error Objects are not valid as a React child (found: object with keys {id, name})
- getting error about objects are not valid as a React child
- Objects are not valid as a React child error in Datatable
- Objects are not valid as a React child -> Build time error -> next js typescript
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. error
- React Typescript - Error Objects are not valid as a React child
- Objects are not valid as a React child - Cannot resolve error
- Can't render Objects inside JSX. Throwing error Objects are not valid as a React child (found: [object Promise])
More Query from same tag
- Should I declare contract every time in React.js?
- Check data exists in sanity with next.js
- reactjs onclick inside map
- how do i access the required data using map and key
- ReactJS 2D arrays
- Use lodash groupBy function to categorize objects in an array
- Setting Multiple state using common function in React Hooks
- Unable to pass down state using react context
- Material-UI: unsupported non-unitless line height with grid alignment. Use unitless line heights instead
- How do I deploy an react app to azure and change the default page
- Hide and show table columns by Checkbox check/uncheck
- problem with router and privaterouter / history
- How to pass json data object {items.symbol} value to another class
- React FlatList renderItem
- localStorage getting updated with initial state value on refresh
- Why is my state not updating after useDispatch
- Why is redux-form throwing an error?
- using history with react-router-dom v6
- Uncaught TypeError: Cannot read properties of undefined (reading '0')
- React Typescript list mapped table row not rendering
- React component error message using filter method
- Why img path works but not with path.join?
- React: Saved state updates the DOM but not the console
- React +getting value from queryString
- How to create a HighCharts chart in react
- Gatsby - Build website for stage/development - which command should I use?
- how to add normalize.css in index.scss file with react app
- Using react context with react hooks in typescript
- How can I center my header buttons and push items to the far right of my toolbar?
- If else in react.js(basic)