S. Hesam
S. Hesam

Reputation: 6603

React said: "Can not find namespace..." in creation of Context

I create a Context in React.js with TypeScript but this error had occurred: Cannot find namespace 'JobContext'.ts(2503)

import React, { createContext, useState }       from 'react';

export const JobContext = createContext<any>({});

const JobContextProvider = ({ children }) => {

    const [data, setData] = useState<any>();

    const updatingState = (newData) => setData({ ...data, ...newData });

    return (
        <JobContext.Provider value={{data, updatingState}}>
            {children}
        </JobContext.Provider>
    );

};

export default JobContextProvider;

Upvotes: 9

Views: 4203

Answers (1)

S. Hesam
S. Hesam

Reputation: 6603

Because as React has said, the extension of your file is .ts, which should be .tsx.

Upvotes: 31

Related Questions