Skip to content

Commit

Permalink
Update RecoilRootProps type for React 18 types (#1718)
Browse files Browse the repository at this point in the history
Summary:
Fixes facebookexperimental/Recoil#1717

Since types/react v18, Implicit `children` was removed from `React.FC`. This change works for types/react v18 and earlier.
DefinitelyTyped/DefinitelyTyped#56210

Pull Request resolved: facebookexperimental/Recoil#1718

Reviewed By: drarmstr

Differential Revision: D35501855

Pulled By: mondaychen

fbshipit-source-id: cf469b96a5220966718270e43e3f0503e144acf3
  • Loading branch information
jackwolfskin0302 authored and facebook-github-bot committed Apr 12, 2022
1 parent 14c218b commit 28407e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion typescript/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
export type RecoilRootProps = {
initializeState?: (mutableSnapshot: MutableSnapshot) => void,
override?: true,
} | {override: false};
children: React.ReactNode,
} | {
override: false,
children: React.ReactNode,
};

/**
* Root component for managing Recoil state. Most Recoil hooks should be
Expand Down
14 changes: 11 additions & 3 deletions typescript/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
useRecoilState_TRANSITION_SUPPORT_UNSTABLE,
useRecoilValueLoadable_TRANSITION_SUPPORT_UNSTABLE,
} from 'recoil';
import * as React from 'react';

/* eslint-disable @typescript-eslint/no-explicit-any */

Expand Down Expand Up @@ -159,7 +160,7 @@ const selectorError3 = selector({
selectorError3;

// RecoilRoot
RecoilRoot({});
RecoilRoot({children: React.createElement('div')});
RecoilRoot({
initializeState: ({ set, reset }) => {
set(myAtom, 5);
Expand All @@ -170,9 +171,16 @@ RecoilRoot({
setUnvalidatedAtomValues({}); // $ExpectError
set(writeableSelector, new DefaultValue());
},
children: React.createElement('div'),
});
RecoilRoot({
override: true,
children: React.createElement('div'),
});
RecoilRoot({
override: false,
children: React.createElement('div'),
});
RecoilRoot({override: true});
RecoilRoot({override: false});

// Loadable
function loadableTest(loadable: Loadable<number>) {
Expand Down

0 comments on commit 28407e4

Please sign in to comment.