Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

counter example using classes react without jsx

<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<div id='root'></div>
<script>
class Hello extends React.Component {
 constructor(props) {
        super(props)
        this.state = {
            count: 0
        }
    }

  render() {
    return React.createElement('div', null, React.createElement("button",{onClick: () => this.setState({ count: this.state.count + 1})}, "Inc "+ this.state.count));
  }
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(React.createElement(Hello, {toWhat: 'World'}, null));
</script>
 
PREVIOUS NEXT
Tagged: #counter #classes #react #jsx
ADD COMMENT
Topic
Name
6+3 =