First react component

Buat folder baru dengan nama components, dan buat file di dalam nya dengan nama counter.jsx

counter.jsx

import React, { Component }  from 'react';

class Counter extends Component {
    state = {}
    render() {
        return <h1>Hello Word</h1>;
    }
}

export default Counter

Masuk ke file index.js, dan panggil file counter.jsx

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.css';
import Counter from './components/counter';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <Counter />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

Last updated

Was this helpful?