tsx

TypeScript and ReactDOM.render method doesn't accept component

守給你的承諾、 提交于 2020-05-25 17:06:28
问题 TL;DR I'm using TypeScript and React. I've defined my AppContainer.tsx component, exported it as default. I'm consuming this in the file app.ts where ReactDOM lives to render it to the targetted dom element. But there I receive the following errors (see image). Read below for more information and links to GitHub repo. Question: What am I doing, or interpreting, wrong? From all code examples I've seen this should work - but maybe (clearly) I'm missing something. Below is more info and links to

TypeScript and ReactDOM.render method doesn't accept component

非 Y 不嫁゛ 提交于 2020-05-25 17:05:59
问题 TL;DR I'm using TypeScript and React. I've defined my AppContainer.tsx component, exported it as default. I'm consuming this in the file app.ts where ReactDOM lives to render it to the targetted dom element. But there I receive the following errors (see image). Read below for more information and links to GitHub repo. Question: What am I doing, or interpreting, wrong? From all code examples I've seen this should work - but maybe (clearly) I'm missing something. Below is more info and links to

TypeScript and ReactDOM.render method doesn't accept component

↘锁芯ラ 提交于 2020-05-25 17:05:35
问题 TL;DR I'm using TypeScript and React. I've defined my AppContainer.tsx component, exported it as default. I'm consuming this in the file app.ts where ReactDOM lives to render it to the targetted dom element. But there I receive the following errors (see image). Read below for more information and links to GitHub repo. Question: What am I doing, or interpreting, wrong? From all code examples I've seen this should work - but maybe (clearly) I'm missing something. Below is more info and links to

Typescript RefForwardingComponent not working

时光毁灭记忆、已成空白 提交于 2020-02-24 10:07:11
问题 I am trying to make my component accept a ref. I have a component like so: const MyComponent: RefForwardingComponent<HTMLDivElement, IMyComponentProps> = (props, ref) => { return <div ref={ref}>Hoopla</div> } But when I try to pass a ref to is like so: <MyComponent ref={myRef}></MyComponent> ... I get this error: Property 'ref' does not exist on type 'IntrinsicAttributes & IMyComponentProps & { children?: ReactNode; }'.ts(2322) What am I doing wrong? 回答1: Your code is right but you are

Typescript RefForwardingComponent not working

ⅰ亾dé卋堺 提交于 2020-02-24 10:06:07
问题 I am trying to make my component accept a ref. I have a component like so: const MyComponent: RefForwardingComponent<HTMLDivElement, IMyComponentProps> = (props, ref) => { return <div ref={ref}>Hoopla</div> } But when I try to pass a ref to is like so: <MyComponent ref={myRef}></MyComponent> ... I get this error: Property 'ref' does not exist on type 'IntrinsicAttributes & IMyComponentProps & { children?: ReactNode; }'.ts(2322) What am I doing wrong? 回答1: Your code is right but you are

Cannot use JSX unless the '--jsx' flag is provided

霸气de小男生 提交于 2020-02-17 18:04:02
问题 I have looked around a bit for a solution to this problem. All of them suggest adding "jsx": "react" to your tsconfig.json file. Which I have done. Another one was to add "include: []" , which I have also done. However, I am still getting the error when I am trying to edit .tsx files. Below is my tsconfig file. { "compilerOptions": { "module": "commonjs", "target": "es5", "allowJs": true, "checkJs": false, "jsx": "react", "outDir": "./build", "rootDir": "./lib", "removeComments": true,

Cannot use JSX unless the '--jsx' flag is provided

瘦欲@ 提交于 2020-02-17 18:01:48
问题 I have looked around a bit for a solution to this problem. All of them suggest adding "jsx": "react" to your tsconfig.json file. Which I have done. Another one was to add "include: []" , which I have also done. However, I am still getting the error when I am trying to edit .tsx files. Below is my tsconfig file. { "compilerOptions": { "module": "commonjs", "target": "es5", "allowJs": true, "checkJs": false, "jsx": "react", "outDir": "./build", "rootDir": "./lib", "removeComments": true,

React Component children typecheck with typescript

雨燕双飞 提交于 2019-12-22 05:40:14
问题 Here is the scenario: I have a custom component: class MyComponent extends React.Component { render () { return ( <SuperComponent> <SubComponent1 /> // <- valid child </SuperComponent> ) } class MyComponent extends React.Component { render () { return ( <SuperComponent> <SubComponent2 /> // <- No! It's not right shape </SuperComponent> ) } and the referenced SuperComponent and SubComponent1 are: interface superPropsType = { children: ReactElement<subPropsType1> } class SuperComponent extends