Next.jsの中で使うReact.jsの記法やよく使う方法をまとめていきます。
import { auth } from '@/lib/firebase.js' useEffect(async () => { if (auth.currentUser) { // 処理 } }, [auth.currentUser])
reactjs - React Redux Store updating, but component not re-rendering - Stack Overflow
function Index () { const boardList = () => { return items.length < 1 ? null : items && <div> {items.map((item) => <div key={item.id}> {item.name} </div> )} </div> } return ( <> {boardList()} </> ) } export default Index
React Hooksを使用する。
import { useState } from 'react' const [articles, setArticles] = useState([]) useEffect(async () => { if (auth.currentUser) { const data = await ArticleModel.get() setArticles(data) } }, [auth.currentUser])
以下だと検知してくれません。
import { useState } from 'react' let articles = [] useEffect(async () => { if (auth.currentUser) { articles = await ArticleModel.get() } }, [auth.currentUser])