Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Experimental hooks for useTransition() support #1572

Closed
wants to merge 3 commits into from

Conversation

drarmstr
Copy link
Contributor

Summary:
Expose experimental useTransition() support for React 18 by exposing variants of Recoil hooks using a different rendering mode that works with useTransition():

  • useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()
  • useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()
  • useRecoilState_TRANSITION_SUPPORT_UNSTABLE()

Example usage to display previous state while a selector is pending:

function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}

Reviewed By: habond

Differential Revision: D33812933

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Jan 28, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33812933

@drarmstr drarmstr self-assigned this Jan 28, 2022
@drarmstr drarmstr added the enhancement New feature or request label Jan 28, 2022
drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 28, 2022
…1572)

Summary:
Pull Request resolved: facebookexperimental#1572

Expose experimental `useTransition()` support for React 18  by exposing variants of Recoil hooks using a different rendering mode that works with `useTransition()`:

* `useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilState_TRANSITION_SUPPORT_UNSTABLE()`

Example usage to display previous state while a selector is pending:

```
function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}
```

Reviewed By: habond

Differential Revision: D33812933

fbshipit-source-id: a8fb903067b31867c5a24691a19050674f42b7a1
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33812933

drarmstr added a commit to drarmstr/Recoil that referenced this pull request Jan 29, 2022
…1572)

Summary:
Pull Request resolved: facebookexperimental#1572

Expose experimental `useTransition()` support for React 18  by exposing variants of Recoil hooks using a different rendering mode that works with `useTransition()`:

* `useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilState_TRANSITION_SUPPORT_UNSTABLE()`

Example usage to display previous state while a selector is pending:

```
function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}
```

Reviewed By: habond

Differential Revision: D33812933

fbshipit-source-id: 62968b2c855dd75326ee522a5bff6078712fb3e7
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33812933

Summary:
Pull Request resolved: facebookexperimental#1569

Enable unit tests for `useRecoilTransaction()` tests that write state.  Test that subsequent reads in the same transaction obtain the latest value.

Also fix atom effects to use the `'set'` trigger when initiated from a `set()` in a transaction.

Differential Revision: https://www.internalfb.com/diff/D33677172?entry_point=27

fbshipit-source-id: 48edbe74175225bedc9104889a36be32d2765c6d
Summary:
* Add `isRetained()` to `Snapshot` methods
* Remove `undefined` from `type` in `RecoilStateInfo`

Drive-by cleanup of wording in warning when using released snapshots to change pseudo-function name to avoid starting with `use` so it doesn't look like a hook.

Differential Revision: https://www.internalfb.com/diff/D33593402?entry_point=27

fbshipit-source-id: 2f9d5ce58b8d0be27ef755aec9831213495dd955
…1572)

Summary:
Pull Request resolved: facebookexperimental#1572

Expose experimental `useTransition()` support for React 18  by exposing variants of Recoil hooks using a different rendering mode that works with `useTransition()`:

* `useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilState_TRANSITION_SUPPORT_UNSTABLE()`

Example usage to display previous state while a selector is pending:

```
function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}
```

Reviewed By: habond

Differential Revision: D33812933

fbshipit-source-id: e1866dda017a2b4d02406c33f47f698d26d1c8c6
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33812933

@drarmstr drarmstr deleted the export-D33812933 branch January 29, 2022 07:03
AlexGuz23 pushed a commit to AlexGuz23/Recoil that referenced this pull request Nov 3, 2022
Summary:
Pull Request resolved: facebookexperimental/Recoil#1572

Expose experimental `useTransition()` support for React 18  by exposing variants of Recoil hooks using a different rendering mode that works with `useTransition()`:

* `useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilState_TRANSITION_SUPPORT_UNSTABLE()`

Example usage to display previous state while a selector is pending:

```
function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}
```

Reviewed By: habond

Differential Revision: D33812933

fbshipit-source-id: 1c4c80a6d6acfe1626dc815abf6358a02a0d6f5f
snipershooter0701 pushed a commit to snipershooter0701/Recoil that referenced this pull request Mar 5, 2023
Summary:
Pull Request resolved: facebookexperimental/Recoil#1572

Expose experimental `useTransition()` support for React 18  by exposing variants of Recoil hooks using a different rendering mode that works with `useTransition()`:

* `useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilState_TRANSITION_SUPPORT_UNSTABLE()`

Example usage to display previous state while a selector is pending:

```
function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}
```

Reviewed By: habond

Differential Revision: D33812933

fbshipit-source-id: 1c4c80a6d6acfe1626dc815abf6358a02a0d6f5f
eagle2722 added a commit to eagle2722/Recoil that referenced this pull request Sep 21, 2024
Summary:
Pull Request resolved: facebookexperimental/Recoil#1572

Expose experimental `useTransition()` support for React 18  by exposing variants of Recoil hooks using a different rendering mode that works with `useTransition()`:

* `useRecoilValue_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE()`
* `useRecoilState_TRANSITION_SUPPORT_UNSTABLE()`

Example usage to display previous state while a selector is pending:

```
function QueryResults() {
  const queryParams = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const results = useRecoilValue_TRANSITION_SUPPORT_UNSTABLE(myQuerySelector(queryParams));
  return results;
}

function MyApp() {
  const [queryParams, setQueryParams] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(queryParamsAtom);
  const [inTransition, startTransition] = useTransition();
  return (
    <div>
      {inTransition ? <div>[Loading new results...]</div> : ''}
      Results: <React.Suspense><QueryResults /></React.Suspense>
      <button
        onClick={() => {
          startTransition(() => {
            setQueryParams(...new params...);
          });
        }
      >
        New Query
      </button>
    </div>
  );
}
```

Reviewed By: habond

Differential Revision: D33812933

fbshipit-source-id: 1c4c80a6d6acfe1626dc815abf6358a02a0d6f5f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support useTransition() for showing previous Recoil state with Recoil state changes.
2 participants