这是我的代码
const Parent = (props) => <div> {props.children} </div>
it works:
<Parent> <a href="/google">Click here </a> </Parent>
This doesn't work
<Parent> <Abutton /> </Parent>
const Abutton = (props) => <a href="/google">Click here </a>
这是问题
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components)
答案 0 :(得分:1)
</props>
而不是</div>
来关闭标签。const Parent = (props) => <div> {props.children} </div>
<Abutton />
需要关闭。我在这里附上了工作片段。
const Parent = (props) => <div> {props.children} </div>
const AButton = (props) => <a href="/link"> Link </a>
ReactDOM.render(
<Parent><AButton /></Parent>,
document.body
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>