About 30-45 minutes Lesson: 10 min Guided Practice:15 min Check for Understanding:20 min
There is not touch prerequisites for learning JavaScript. Here are some of the prerequisite for learning JavaScript:
Basic programming knowledge. Knowledge of core Java sufficient.
You should have knowledge of HTML. Check HTML tutorials here.
Why it is worth learning React Modularity?
import
and export
support our ability to build modular codeReact is a JavaScript library (not a framework) that creates user interfaces (UIs) in a predictable and efficient way using declarative code. You can use it to help build single page applications and mobile apps, or to build complex apps if you utilise it with other libraries. React works in declarative code. For more reference
Modular code is code that is separated into segments (modules), where each file is responsible for a feature or specific functionality.
Developers separate their code into modules for many reasons:
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Faisal Arkan" />;
ReactDOM.render(
element,
document.getElementById('root')
);
name="Faisal Arkan"
will give value into {props.name}
from function Welcome(props)
and returning a component that has given value by name="Faisal Arkan"
. After that React will render the element into html.
class Cat extends React.Component {
constructor(props) {
super(props);
this.state = {
humor: 'happy'
}
}
render() {
return(
<div>
<h1>{this.props.name}</h1>
<p>
{this.props.color}
</p>
</div>
);
}
}
const Cat = props => {
return (
<div>
<h1>{props.name}</h1>
<p>{props.color}</p>
</div>;
);
};
class Hogwarts extends React.Component {
render() {
return (
<div className="Hogwarts">
"Harry. Did you put your name in the Goblet of Fire?"
</div>
);
}
}
It’s standard practice to give each of these components their own file. It is not uncommon to see a React program file tree that looks something like this:
├── README.md
├── public
└── src
├── App.js
├── Hogwarts.js
└── Houses.js
For example:
// src/houses/HagridsHouse.js
import React from 'react';
function whoseHouse() {
console.log(`HAGRID'S HOUSE!`);
}
export default whoseHouse;