简体   繁体   English

高级 React Typescript 功能组件声明

[英]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} />
  1. DemoProps is the interface for your props and makeMapStateToProps is that for the state. DemoProps是道具的接口,而makeMapStateToProps是状态的接口。
  2. The props received by the state are destrutured out as props1 and props2 state 收到的 props 被解构为 props1 和 props2
  3. Those props are then passed on to the in render method.然后将这些道具传递给 in 渲染方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM