0

im getting this weird error in console.log while trying to fetch data from a bearer token API

dispatchSetState(fiber, queue, action) {
      {
        if (typeof arguments[3] === 'function') {
          error("State updates from the useState() and useReducer() Hooks don't support the " + 'sec…

after trying to fetch the data from a Bearer token API using Reactjs.

here is my code:

  const [result, setResult] = useState();
  useEffect(() => {
    fetch("https://myapi.com/api/products", {
      method: "GET",
      headers: { Authorization: `Bearer ${accessToken}` },
    })
      .then((res) => res.json())
      .then((json) => setResult(json));
    console.log(setResult);
  }, []);

what am i doing wrong?

1 Answer 1

1

Actually, it is not an error, you need to console.log(result) in outside of useEffect not console.log(setResult);,

Sign up to request clarification or add additional context in comments.

5 Comments

thank u for u answer it kinda works but it kept giving me the same result above the data
did you console.log(result) and still get the same error?
You need to remove console.log(setResult);
i removed it and put it outside useEffect because i need to check the result
yes but now console.log(result) check You have confused setResult and result. useState returns the current state and a function that updates it. The first one "result" is the state and the second one setResult is the function no need to console that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.