Search code examples
reactjscodesandbox

React Context not running in CodeSandBox


I'm trying to run this React Context example in codesandbox, but getting this error:

Invariant Violation

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of `MyProvider`.

I have React set to 16.3 and the code itself was pulled directly from this Wes Bos example. I've looked over the code a handful of times but I'm not seeing any problems. Could it be a context setting with codesandbox I'm not understanding?


Solution

  • You'll also have to use a 16.3 version of react-dom. In your sandbox react is 16.3.0 and react-dom is 16.2.0. Here's a sandbox with a working example: https://codesandbox.io/s/1r1j221nl3