reactjs.org tutorial code example
Example 1: react js documentation
//With node and npm already installed for basic start
npx create-react-app my-app-name
// if you want to use npm
npx create-react-app my-app-name --npm
//if you want to use typescript
npx create-react-app my-app-name --template typescript
yarn start // app will be hosted on localhost:3000
/* start making changes at ./my-app-name/src/App.js
React documentation: https://reactjs.org/docs/hello-world.html
*/
Example 2: react tutorial for beginners
import React from 'react';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: 'Initial data...'
}
this.updateState = this.updateState.bind(this);
};
updateState() {
this.setState({data: 'Data updated...'})
}
render() {
return (
<div>
<button onClick = {this.updateState}>CLICK</button>
<h4>{this.state.data}</h4>
</div>
);
}
}
export default App;
Example 3: react tutorial
class Board extends React.Component {
constructor(props) { super(props); this.state = { squares: Array(9).fill(null), }; }
renderSquare(i) {
return <Square value={i} />;
}
Example 4: react tutorial
renderSquare(i) {
return <Square value={i} />;
}
Example 5: react tutorial
As far as I can tell from looking, codecademy, w3schools,
and many answers on stack overflow are all outdated.
The best option is "https://reactjs.org/"