React Hooks — useEffect

import React, {useEffect, useState} from 'react';
render > useEffect > setState > re-render > useEffect
useEffect (() => {
console.log("UseEffect called");
//fetch
}, [] //dependency array if empty, only runs once!
useEffect(() => {
console.log("UseEffect called");
//fetch
}, [count]
const [strains, setStrains] = useState([]);const [searchTerm, setSearchTerm] = useState("")useEffect(() => {fetch("http://localhost:3000/strains").then((r) => r.json()).then((strains) => setStrains(strains));}, []);
useEffect(() => {})
useEffect(() => {}, [])
useEffect (() => {}, [variable1, variable2])

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store