Hello, is there another way to pull out just one item from an array?
For example, I want only array
variable from DataContext
but to do that I have to do it like this:
let [data, setData, array, setArray] = useContext(DataContext);
Here I don’t need three other array items but I have to write it that way in order to get the one I want. Is there another syntax for this?
What does useContext()
return?
An array of items
[data, setData, array, setArray, items, setItems]
did you try destructuring?
const {data}=useContext(DataContext)
Is that useContext
the hook React provides (eg React.useContext
)?
.edit: yeah, if it is React’s useContext hook, then that returns the value
of the context. Which is always an objects so what @sayinmehmet47 says should be correct: why are you instead getting an array?