reactjs - TypeScript ReactDOM Property 'type' is missing on component -
getting following error:
error ts2345 argument of type 'typeof somecomponent' not assignable parameter of type 'reactelement<{}>'. property 'type' missing in type 'typeof somecomponent'.
got following code typescript code:
import * react 'react'; import * reactdom 'react-dom'; interface iprops{} interface istate {} class somecomponent extends react.component<iprops, istate> { render() { return <div />; } } var component = somecomponent; var root = document.getelementbyid("root"); reactdom.render(component , root);
i tried following:
class somecomponent extends react.component<iprops, istate> { render() { return <div />; } type() { return "test"; } }
should like:
interface iprops{} interface istate {} class somecomponent extends react.component<iprops, istate> { render() { return <div />; } } reactdom.render(<somecomponent /> , document.getelementbyid("root"));
you don't pass component class render
function, need pass instance.
edit
this:
var component = somecomponent;
assigns reference class somecomponent
component
variable, meaning if can both , same:
var componentinstance1 = <somecomponent /> var componentinstance2 = <component />
if don't want use jsx/tsx notation when constructing component need pass props:
var component = new somecomponent(props);
Comments
Post a Comment