reactjs – 如何在Typescript React中遍历Component的Children?
发布时间:2020-12-15 20:50:07 所属栏目:百科 来源:网络整理
导读:如何在Typescript tsx中遍历React组件的子项? 以下是有效的jsx: public render() { return ( div {React.Children.map(this.props.children,x = x.props.foo)} /div );} 但是,在Typescript中,x的类型是React.ReactElement any所以我无法获得道具.我需要做
如何在Typescript tsx中遍历React组件的子项?
以下是有效的jsx: public render() { return ( <div> {React.Children.map(this.props.children,x => x.props.foo)} </div> ); } 但是,在Typescript中,x的类型是React.ReactElement< any>所以我无法获得道具.我需要做某种铸造吗?
是.也更喜欢断言一词.一个快速的: React.Children.map(this.props.children,x => (x as any).props.foo) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |