<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christopher McClister</title>
    <description>The latest articles on DEV Community by Christopher McClister (@cmcclister).</description>
    <link>https://dev.to/cmcclister</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2000505%2Fb88f9b6f-2e10-4f9a-9a25-ad9c9a041411.png</url>
      <title>DEV Community: Christopher McClister</title>
      <link>https://dev.to/cmcclister</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cmcclister"/>
    <language>en</language>
    <item>
      <title>"SyntaxError: Cannot use import statement outside a module" error with createContext and useReducer</title>
      <dc:creator>Christopher McClister</dc:creator>
      <pubDate>Thu, 29 Aug 2024 23:30:50 +0000</pubDate>
      <link>https://dev.to/cmcclister/syntaxerror-cannot-use-import-statement-outside-a-module-error-with-createcontext-and-usereducer-4nph</link>
      <guid>https://dev.to/cmcclister/syntaxerror-cannot-use-import-statement-outside-a-module-error-with-createcontext-and-usereducer-4nph</guid>
      <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I am getting the following error when trying to create a Context Provider file:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;\src\helpers\GlobalContextProvider.js:1&lt;br&gt;
import React from 'react';&lt;br&gt;
^^^^^^&lt;br&gt;
SyntaxError: Cannot use import statement outside a module&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My installation of React is recent, I've confirmed that my version of Typescript is updated, tsconfig.json is set up for ES6, and all of the other things that a web search suggests when encountering this issue. I'm hoping someone here can help to understand what I am doing wrong. I've included the code below. I believe it is a simple, standard set up, based upon tutorials and code examples that I've seen. FYI, I was originally using "import" for createContext and useReducer, but doing so produced the same error above for them as well. Any help with this would be greatly appreciated. Thank you!&lt;/p&gt;

&lt;p&gt;The code for GlobalContextProvider.js:&lt;/p&gt;

&lt;p&gt;import React from 'react';&lt;br&gt;
const createContext = require('react');&lt;br&gt;
const useReducer = require('react');&lt;/p&gt;

&lt;p&gt;const GlobalStateContext = createContext({});&lt;br&gt;
const GlobalDispatchContext = createContext({});&lt;/p&gt;

&lt;p&gt;const initialState = {&lt;br&gt;
  dbConfig: {},&lt;br&gt;
  dbQuery: ""&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;const reducer = (state, action) =&amp;gt; {&lt;br&gt;
  switch (action.type) {&lt;br&gt;
    case 'SET_CONFIG_OBJECT': {&lt;br&gt;
      return {&lt;br&gt;
        ...state,&lt;br&gt;
        dbConfig: state.dbConfig,&lt;br&gt;
      };&lt;br&gt;
    }&lt;br&gt;
    case 'SET_QUERY_STATE': {&lt;br&gt;
      return {&lt;br&gt;
        ...state,&lt;br&gt;
        dbQuery: state.dbQuery,&lt;br&gt;
      };&lt;br&gt;
    }&lt;br&gt;
    default:&lt;br&gt;
      throw new Error('Bad Action Type');&lt;br&gt;
  }&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;const GlobalContextProvider = ({ children }) =&amp;gt; {&lt;br&gt;
  const [state, dispatch] = useReducer(reducer, initialState);&lt;br&gt;
  return (&lt;br&gt;
    &lt;br&gt;
      &lt;br&gt;
        {children}&lt;br&gt;
      &lt;br&gt;
    &lt;br&gt;
  );&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;module.exports = {&lt;br&gt;
    GlobalContextProvider&lt;br&gt;
}&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
