通过函数在子组件中向下传递变量的道具类型应该是什么

What should be the prop type of passing a variable down in a child component via function

给定以下组件:

Component.propTypes = {
  // not right:
  children: PropTypes.oneOfType([
    PropTypes.arrayOf(PropTypes.node),
    PropTypes.node,
  ]),
}

export default function Component({ children }) {
  return children({ someValue: "foobar" });
}
AnotherComponent.propTypes = {
  value: PropTypes.string,
}

export default function AnotherComponent({ value }) {
  return <p>{value}</p>
}

像这样使用:

<Component>
 {(someValue) => (<AnotherComponent value={someValue} />)}
</Component>

给出错误:Warning: Failed prop type: Invalid prop 'children' supplied to 'Component'.

这个的proptype是什么?

尝试 PropTypes.func:

Component.propTypes = {
  children: PropTypes.func
};

至于"real-life"例子,你可以查看children type of AutoSizer [2]