Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 何时使用React.PropsWithChildren_Reactjs_Typescript_React Props - Fatal编程技术网

Reactjs 何时使用React.PropsWithChildren

Reactjs 何时使用React.PropsWithChildren,reactjs,typescript,react-props,Reactjs,Typescript,React Props,在我看来是两种相似的设置,在一台机器上,我被允许呼叫 <MyApp accountId={this.props.accountId} children={toggleButton} /> 我不确定为什么它在一种设置中工作,而在另一种设置中不工作。我什么时候在React.PropsWithChildren中包装我的道具界面 我最好的猜测是,在React或React相关包的打字文件中可以找到更改。我不知道为什么它在一台机器上工作,但在另一台机器上不工作,

在我看来是两种相似的设置,在一台机器上,我被允许呼叫

<MyApp
        accountId={this.props.accountId}
        children={toggleButton} />
我不确定为什么它在一种设置中工作,而在另一种设置中不工作。我什么时候在
React.PropsWithChildren
中包装我的道具界面


我最好的猜测是,在React或React相关包的打字文件中可以找到更改。

我不知道为什么它在一台机器上工作,但在另一台机器上不工作,但我认为这不是使用
children
属性的正确方法

而不是这个

<MyApp
        accountId={this.props.accountId}
        children={toggleButton} />
。。。或者类似的


在我上面的例子中,一个子或多个子--
,可能是一个React元素,或者文本(文本节点),或者如果没有子元素,则可能是
未定义的
,或者可能是一个像
{toggleButton}
这样的表达式,它的计算结果是其中一个子类型。

我自己以及React中的一个新手对此感到奇怪,投票通过了,希望我们都能得到答案
class MyApp extends React.Component<React.PropsWithChildren<IMyAppProps>, IMyAppState> {
<MyApp
        accountId={this.props.accountId}
        children={toggleButton} />
<MyApp accountId={this.props.accountId}>
  <ToggleButton/>
</MyApp>