I'm confused why the isLoading flag is set to true in the initial state. Isn't it supposed to be false initially? Consider this simple example:
const SearchCharity = () => {
const [isLoading, setIsLoading] = useState(true)
const [themes, setThemes] = useState([])
useEffect(() => {
const fetchThemes = async () => {
try {
setIsLoading(true)
const result = await axios.get(url)
setThemes(result.data.themes.theme)
setIsLoading(false)
} catch (err) {
console.log(err)
}
}
fetchThemes()
}, [])
return (
{
isLoading ? <h1>Loading......</h1> : <h1>Display Content</h1>
}
)
export default SearchCharity
Another thing it, if we set it to true or false initially in the above code, the useEffect still runs the same and the result on the screen will also be the same. So, why true? Is this some sort of standard?