React (Hooks) code example
Example 1: react hooks
const [state, setState] = useState(initialState);
Example 2: react hooks
import React, { useState, useEffect } from 'react';
function Example() {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
Example 3: components react to hooks
import React, { useState } from 'react';
function Example() {
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}