Partial Reactization of existing projects It looks good to start with this temp when making a new one. https://reactjs.org/docs/add-react-to-a-website.html
Build the tool chain only after you feel the need to do so (when it becomes sufficiently complex). https://reactjs.org/docs/create-a-new-react-app.html
onClick is received by handleClick https://reactjs.org/docs/handling-events.html
Props are read-only https://reactjs.org/docs/components-and-props.html#props-are-read-only I see. Separation of model and view. To update the state, pass a function to this.setState that takes the previous state as an argument, creates a new state, and returns it.
Component called "Circle that changes color when clicked. https://codepen.io/nishiohirokazu/pen/YOWqKw
Too many things can be done in the browser without creating your own development environment, which makes it a hassle to create your own development environment, but it is also hard to develop all the time only in the browser. But that's not an option. https://reactjs.org/tutorial/tutorial.html#setup-option-2-local-development-environment
With SVG
JSX to write HTML-like things in JS code
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
Conversion with Babel
https://github.com/tanem/react-svg
js
const e = React.createElement;
class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}
render() {
if (this.state.liked) {
return 'You liked this.';
}
return e(
'button',
{ onClick: () => this.setState({ liked: true }) },
'Like'
);
}
}
ReactDOM.render(
e(LikeButton),
document.getElementById('root')
);
console.log('OK')
https://reactjs.org/docs/add-react-to-a-website.html
:
<svg width="100" height="100" id="canvas">
<circle cx="50" cy="50" r="40" stroke="green" strokeWidth="4" fill="yellow" />
</svg>
js
handleClick(e) {
console.log("clicked");
this.setState(prevState => {
console.log(prevState);
return {
value: !prevState.value
};
});
}
This page is auto-translated from /nishio/React using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.