0

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) 
3
  • You are lacking a / for <Abutton /> Commented Mar 16, 2020 at 2:43
  • edited the syntax Commented Mar 16, 2020 at 2:45
  • You have a typo in your code. Abutton is missing the / for the self-closing tag. Commented Mar 16, 2020 at 2:46

1 Answer 1

1
  1. You have mistakenly added </props> instead of </div> to close the tag.
const Parent = (props) => <div> {props.children} </div>
  1. <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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.