Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

javascript - useTransition - Object is not a function or its return value is not iterable

I'm running the experimental version of React to play with Concurrent mode and useTransition. The versions I'm running are:

"react": "0.0.0-experimental-27659559e",
"react-dom": "0.0.0-experimental-27659559e",

I've also made sure that I've opted for Concurrent mode from index.js:

ReactDOM.unstable_createRoot(document.getElementById("root")).render(<App />);

The component I'm trying to use useTransition on looks like this -

import React, { Suspense, useState, useTransition } from "react";
import { createResource } from "./utils";

const initialResource = createResource();

const UserInfo = () => {
  const [resource, setResource] = useState(initialResource);
  const [startTransition, isPending] = useTransition({
    timeoutMs: 3000,
  });
  const user = resource.invoice.read();
  return (
    <div>
      <span>{user.name}</span>
      <button onClick={() => setResource(createResource())}>Load data</button>
    </div>
  );
};

Everything works fine until I implement the line with useTransition. The app breaks and throws an error saying TypeError: Object is not a function or its return value is not iterable highlighting the following line:

const [startTransition, isPending] = useTransition({
    timeoutMs: 3000,
  });

I'm not sure if there's an issue with setting up Concurrent mode. This is similar to what the official doc is saying for setting up useTransition. Can anyone give me some idea as to what might be going wrong here?

question from:https://stackoverflow.com/questions/65853644/usetransition-object-is-not-a-function-or-its-return-value-is-not-iterable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...