Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find namespace React Context TypeScript

import React, { useState, createContext, FC } from "react";
import {
  InitialInputValues,
  InputsInitiaState,
} from "../components/AccountDetails/AccountDetails.type";

export const TestContext = createContext<InputsInitiaState>(InitialInputValues);

const TodoProvider: FC<React.ReactNode> = ({ children }) => {
  const [inputs, setInputs] = useState<InputsInitiaState>(InitialInputValues);
  return <TestContext.Provider value={inputs}>{children}</TestContext.Provider>;
};

I have the follwing problem I have created the context and I am trying to return the children component in order to pass the context ot the app but TypeScript is saying that TestContext cannot find namespace of it. I have researched in alot of places and all are showing the same way of handling with context, can some one take a look and point out what I am missing, thanks in advance. I am gonna share a picture as well of the error enter image description here

like image 649
NewInTown Avatar asked Mar 01 '26 07:03

NewInTown


1 Answers

It looks like your file is being parsed as TypeScript instead of "TypeScript React" (i.e. TS with JSX).

That's why it's trying to read your JSX tag as a type.

like image 87
tbjgolden Avatar answered Mar 02 '26 23:03

tbjgolden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!