remix icon indicating copy to clipboard operation
remix copied to clipboard

useTransition() does not give a valid value

Open Baedonghee opened this issue 3 years ago • 2 comments

What version of Remix are you using?

^1.7.2

Steps to Reproduce

As shown in the document, when it is post, it goes to idle → submitting → loading → idle, but it goes to idle -> submitting -> idle. Add the code below.

The folder structure is also in route

const data = useActionData();
  const transition = useTransition();
  console.log(transition);

  const loadText = {
    actionSubmission: "submit!!",
    actionReload: "loading",
  };

  const btnText = loadText[transition.type] || "submit";

  return (
    <div>
      <h1>useActionData</h1>
      <Form method="post">
        <p>firstname:</p>
        <input type="text" name="firstname" />
        <br />
        <p>lastname:</p>
        <input type="text" name="lastname" />
        <br />
        <p>years:</p>
        <input type="number" name="years" />
        <br />
        <button type="submit">{btnText}</button>
        <br />
        <p>{data ? data.message : "none"}</p>
      </Form>
    </div>
  );

Expected Behavior

As shown in the document, when it is post, it should proceed with idle → submitting → loading → idle.

Actual Behavior

idle -> submitting -> idle.

Baedonghee avatar Oct 07 '22 08:10 Baedonghee

Your code example is busted. Can you update your issue?

kiliman avatar Oct 07 '22 13:10 kiliman

@kiliman done

machour avatar Oct 14 '22 16:10 machour

I am assuming this is because there are no defined loaders. Since there is nothing to load the router is able to go right back to idle and skip an in-between react render for state: "loading". I tested on 1.16.0 and this is the behavior I'm seeing with the above code.

If you have loaders and are experiencing this issue, could you provide a reproduction via https://remix.new?

brophdawg11 avatar May 05 '23 15:05 brophdawg11