What really should you pass into createContect()?

37 Views Asked by At

I see all of the following forms:

  1. createContext()
  2. createContext(null)
  3. createContext({})
  4. createContext(theme: 'light', toggleTheme: () => {})

example of #4 is here. So can you just use #1 or #2 above and they are the same as #3 or #4?

#4 above seem like it has an empty function that somehow miraculously becomes something else? (because empty function. is not useful and supposedly it should do something). I sometimes see a

createContext(isFooBar: false, setIsFooBar: () => {})

as if somehow the setIsFooBar() will become a function that can alter the flag isFooBar. How does it really work?

0

There are 0 best solutions below