Hey I’ve been trying React, total newbie but this component mainIntro.js is not getting imported into the main react component App.js. I’d appreciate if anyone can help me figure out how this works !
EDIT: I’m using CDN links for React and ReactDOM because I was trying this out on a friend’s laptop.
mainIntro.js
const mainIntro = props => (
<div id="quote-box">
<h1> Hunter x Hunter Quotes </h1>
<div id="text">
"When I say it doesn't hurt me, that means I can bear it."
</div>
<div id="author">
- Killua Zoldyck
</div>
<button id="new-quote"> Next Quote </button>
<a href="#" id="tweet-quote" target="_blank"> Tweet this quote </a>
</div>
)
export default mainIntro;
It’s probably because the way you are writing your component. You are using a functional component, but there’s an error in your code. It should be:
const MainIntro = props => {
return (
<div id="quote-box">
//... rest of the code
</div>
);
}
Notice that you are not using curly brackets after the arrow and you are not returning anything either. This is not a React thing, this is JavaScript syntax. I’d suggest you to read more about arrow functions and ES6 features since you are going to see them a lot in React apps.
Also use the documentation, I find React official docs to be very helpful unlike other documentations.
I am using VS Code and also I have a fair grip over ES6 and React ( theory ). I’ve finished the Front End Certification and this was for one of the final projects
Yep it’s all the same. I’m pretty sure it’s not working due to the CDN. I’ll install React on this laptop ( it’s my friend’s ) and try again. I don’t know where to put the React app afterwards though ? I mean is Heroku the only way or are there easier ways ? I need to put the link on FCC’s certifcations page.
I’m not familiar with the CDN, the only way to be 100% sure is if you drag your code to codesanbox for example and see if it works. You can use GitHub to deploy your react app as long as it’s static site (no back-end stuff).