if you occure below cord
index.js:2178 Warning: An Effect function must not return anything besides a function, which is used for clean-up.
It looks like you wrote useEffect(async () => ...) or returned a Promise. Instead, you may write an async function separately and then call it from inside the effect:
async function fetchComment(commentId) {
// You can await here
}
useEffect(() => {
fetchComment(commentId);
}, [commentId]);
make sure that your code at useEffect
now is
function Some() {
const [posts, setPosts] = useState([]);
useEffect(
async () => {
const res = await fetch('https://www.reddit.com/r/reactjs.json');
const json = await res.json();
setPosts(json.data.children.map(c => c.data));
}
);
fix to
function Some() {
const [posts, setPosts] = useState([]);
useEffect(
async () => {
const res = await fetch('https://www.reddit.com/r/reactjs.json');
const json = await res.json();
setPosts(json.data.children.map(c => c.data));
},[setPosts]// add here
);
This reason that useEffect called every render and call fetch, update state, after state update, render Component...and call fetch...
So that setPosts is call when component rendered only one. setPosts itself not update. stop useEffect
Try to use async with explicit function inside useEffect().
const [posts, setPosts] = useState([]);
useEffect(() => {
async function fetchComment() {
const res = await fetch('https://www.reddit.com/r/reactjs.json');
const json = await res.json();
setPosts(json.data.children.map(x => x.data));
}
fetchComment()
}, [setPosts]);
======================|| Learn C# ||===========================
C# Constructor
C# Enum
C# String
C# Namespace
C# Casting
=========================================================