嘿伙計們,我是 React js 的新手,我收到了這個錯誤TypeError: Cannot read property 'map' of undefined,我嘗試了對象的 console.log 并且它顯示了所有結果但是我無法在瀏覽器中顯示它,因為彈出這個錯誤??赡苁鞘裁丛??const search = 'api/posts/search'const [appState, setAppState] = useState({ search: '', posts: [],});const [error, setError] = useState('')useEffect(() => { axiosInstance.get(search + '/' + window.location.search) .then((res) => { const allPosts = res.data; setAppState({ posts: allPosts }); setError(''); // console.log(res.data); }) .catch((errors) => { setAppState({}); setError('Something went wrong!') })}, [setAppState]){/* console.log(appState.posts.results) */}{appState.posts && appState.posts.results.map((post) => { return ( <div key={post.id}> <h5>{post.title}</h5> </div> )}})}謝謝
類型錯誤:無法讀取未定義的屬性“地圖”。反應 js
米琪卡哇伊
2023-05-19 14:42:21