[英]Advanced React Typescript functional component declaration
I'm relatively new to Typescript with React: I've built a few smaller apps in preparation for starting a new job but I'm a bit stuck on the following code.我对使用 React 的 Typescript 还比较陌生:我已经构建了一些较小的应用程序来准备开始一份新工作,但我对下面的代码有点卡住了。 Can someone please explain what's happening in the FunctionComponent declaration please?
有人可以解释一下 FunctionComponent 声明中发生了什么吗?
import * as React from 'react';
import {createStructuredSelector} from 'reselect';
const makeMapStateToProps = () =>
createStructuredSelector({
selectedLinkUrl:'someURL',
selectedLinkComponentId: 'someID'
});
interface DemoProps {
name?: string;
}
const SomeComponent: React.FunctionComponent<DemoProps &
ReturnType<ReturnType<typeof makeMapStateToProps>>> = ({
prop1, prop2
}) => <div prop1={prop1} prop2={prop2} />
Okay let's dig into it:好的,让我们深入研究一下:
const SomeComponent: React.FC<DemoProps &
ReturnType<ReturnType<typeof makeMapStateToProps>>> = ({
prop1, prop2
}) => <div prop1={prop1} prop2={prop2} />
DemoProps
is the interface for your props and makeMapStateToProps
is that for the state. DemoProps
是道具的接口,而makeMapStateToProps
是状态的接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.