-2

I followed the tutorial yet this error isn't being solved](https://i.stack.imgur.com/2qNEF.jpg)

I tried to use {} instead of [] but still the same error occurs

Pranoz
  • 1
  • Please make sure to post code and errors as text directly to the question (and [not as images](https://meta.stackoverflow.com/questions/285551)), and [format them appropriately](https://stackoverflow.com/help/formatting). – juliomalves Oct 30 '22 at 16:13

1 Answers1

0

your useContext return null. And you try to destructure null. If you don't provide array in context provider value then you can't write:

const [a1, a2] = ....

So probably you miss match useState

const [state, setState] = useState

with context

const context = useContext(Context)

So. Just write:

const balance = useContext(BalanceContext);
console.log('balance context:',balance)

and then you will see what is in balance context. if is a object then you have to destructure object.

ps. quick fix to run project:

const [balance, setBalanace] = useContext(BalanceContext) || [];
// balance and setBalance is undefined 
Robert
  • 2,538
  • 1
  • 9
  • 17