reactjs - How to use component which contains actions? Getting error "Type '{}' is not assignable to type 'IntrinsicAttributes" -
i'm trying component have prop actions stuff (such user login through popup eventually):
import { component } 'react'; import * react 'react'; import { connect } 'react-redux'; class props { dostuff() { } } export class test extends component<props, {}> { public render() { return (<div>lol</div>); } }
in layouts.tsx try this:
import * react 'react'; import { navmenu } './navmenu'; import { test } '../test/test' import { component } 'react'; export class layout extends react.component<{}, {}> { public render() { return <div classname='container-fluid'> <div classname='row'> <div classname='col-sm-3'> <navmenu /> </div> <div classname='col-sm-9'> <test /> {this.props.children} </div> </div> </div>; } }
however looks react doesn't action in props..
error in [at-loader] ./clientapp/components/layout.tsx:16:21 ts2322: type '{}' not assignable type 'intrinsicattributes & intrinsicclassattributes & readonly<{ children?: reactnode; }> & read...'. type '{}' not assignable type 'readonly'. property 'dostuff' missing in type '{}'.
my props strings or booleans nclude without issue, how make work functions? if isn't possible can put elsewhere in component?
the problem react likes action in props, you're not providing 1 @ <test/>
. if add method dostuff
layout
, use <test dostuff={this.dostuff}/>
, should work. also, want declare interface props
, instead of class, want declare types there.
Comments
Post a Comment