Built-in Hook useEffect
useEffect(() => { const data = MockedApi.fetchData(); data.then((res) => { res.forEach((e) => { if (e.name === friendName) { setIsPresent(true); } }); }); });
Custom Hook useFriendName
export default function useFriendName(friendName) { const [isPresent, setIsPresent] = useState(false); ... return isPresent; }
Examples coming...
<Counter />
You clicked 0 times
<DataFetcher />
<Clock />
React Hooks are not really new feature that popped out just now. They are another (better ❓) way of doing React components that need to have state and/or lifecycle methods. Actually, they use the same internal logic that is being used currently by the class components.
To use them or not. This is the question that the future will give the best answer of.