Why is this not iterable?
input
is not an array, but an object. Change the for-loop to:
for (let item of Object.values(input)) {
/*rest of the code*/
}
so the iteration is done over the object values rather than the object itself.
Uncaught TypeError: object is not iterable --using context with reducer
The value provided to Context
is an object
{meatState:meatState,dispatchMeatState:dispatchMeatState}
But you're using array destructuring while getting the values
const [meatState, dispatchMeatState ] = useContext(MeatContext)
Using object destructuring should solve it,
const { meatState, dispatchMeatState } = useContext(MeatContext)
object is not iterable JavaScript
You can check if myArray
is object and then convert it to an array of one object.
for(let singleItem of Array.isArray(myObj) ? myObj : [myObj]){
TypeError: Object is not iterable when working with react context
I got behind some tutorials again and found my mistake. I had my .Provider tag in the wrong file. It's supposed to be in the App where the Router is, where you call all the components so they all have access to the context.
function RouterApp() {
const [ board, setBoard ] = useState(null);
const value = useMemo(() => ({ board, setBoard}), [ board, setBoard])
return (
<Router>
<div className="App">
<BoardContext.Provider value={value}>
<Switch>
<Route path="/" exact component={BoardName} />
<Route path="/createboard/:name" exact component={TimePeriod} />
<Route path="/createboard:name/phases" exact component={PhaseForm} />
</Switch>
</BoardContext.Provider>
</div>
</Router>
);
}
export default RouterApp;
Here's my router function, where im passing the context to the components to BoardName, TimePeriod and PhaseForm.
Thanks for everyone helping me.
Related Topics
Regex Pattern to Match the End of a String
Case Insensitive String Replacement in JavaScript
Is There a JavaScript Strcmp()
Accessing the Content of Other Tabs in a Browser
Is There a Downside to Using Es6 Template Literals Syntax Without a Templated Expression
React.Js Replace Img Src Onerror
Why JavaScript Functions Always Return a Value
Spring Boot Controller - Upload Multipart and JSON to Dto
What Does Variable Declaration with Multiple Comma Separated Values Mean (E.G. Var a = B,C,D;)
Getting Image Dimensions Using JavaScript File API
Jquery .Find() Doesn't Return Data in Ie But Does in Firefox and Chrome
Remove Characters from a String
No Semicolon Before [] Is Causing Error in JavaScript
Get Path Params in React-Router V4