3
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

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for pointing that it was the reason I have forgotten to add the x to the end of the file. Thank you. Cheers, I will leave the issue open for any fellas that may have the same small issue :D
I spent 3 hours looking in this error by myself. Regretting not searching online. Thank you so much for the comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.