Do you work with React for some time and try to wrap your head around hooks? Here you can check what's the difference between Class component with lifecycle methods and Function component with useEffect.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useReducer, useEffect } from 'react'; | |
const reducer = (state, updatedProperty) => ({ | |
...state, | |
...updatedProperty, | |
}); | |
const initState = { | |
name: 'John', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useCallback } from 'react'; | |
export function App() { | |
const [counter, setCounter] = useState(0); | |
// const increment = (n) => { | |
// setCounter(c => c + n); | |
// }; | |
const increment = useCallback((n) => { |