【发布时间】:2018-02-10 21:05:26
【问题描述】:
如何将道具从 Gatsby 布局传递给子级(例如 Header 组件)?
import React from "react";
export default ({ children }) => {
return <div>{children()}</div>;
};
我找到的资源使用如下格式:
{ props.children({ ...props, foo: true }) }
{ this.props.children({...this.props, updateLayoutFunction }) }
但是由于没有props,只有孩子,我无法让它工作。我试过了,但也没有用:
{ children({ foo: true }) }
在所有情况下,我都会收到此错误:TypeError: undefined is not an object (evaluating 'history.listen')
https://github.com/gatsbyjs/gatsby/issues/3412#event-1446894145 https://github.com/gatsbyjs/gatsby/issues/2112
【问题讨论】: