Reputation: 2055
here is my code
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>
This is the issue
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components)
Upvotes: 0
Views: 68
Reputation: 4182
</props>
instead of </div>
to close the tag.const Parent = (props) => <div> {props.children} </div>
<Abutton />
needs to be closed.I've attached working snippet here.
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>
Upvotes: 1