-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Rename React's SFC to 'FunctionalComponent' #30364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename React's SFC to 'FunctionalComponent' #30364
Conversation
@rhysforyou Thank you for submitting this PR! 🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @morcerf @tkrotoff @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @icopp - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
@rhysforyou The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
@rhysforyou The PR ##30331 fixing all React tests failing has been merged so I recommend rebasing and it should be much easier to make tests passing here. Also can you please add/change alias SFC to FC? I don't really like such a long name as |
I've rebased and added |
@rhysforyou Unfortunately, this pull request currently has a merge conflict 😥. Please update your PR branch to be up-to-date with respect to master. Have a nice day! |
All fixed up 😄 |
Thanks - could you add a test for back compatibility please? I'd like to see evidence that works as otherwise this will be a very breaking change to the type definitions. Essentially all the tests that exist for |
@johnnyreilly done, I've added back tests that deal with the |
Looks good to me. @kovensky - does this look good to you? |
Looks good to me (can't use review UI as I'm on phone atm). I see you also accidentally(?) ran Prettier on the code ;) |
Oops, I’ll fix that up haha. |
Revert "remove use of deprecated APIs" This reverts commit 6bdf2ed. remove use of deprecated APIs without reformatting
Nothing a little interactive rebasing couldn't fix. Assuming I didn't break anything between all those squashes and reverts, and this PR goes green, it should be ready to merge. |
Thanks |
Is there a reason for releasing this change in a patch version? It is a breaking change and should probably have been released in a major version. |
@amanmahajan7 What's breaking change? Old stuff is just deprecated, but it's still there. You have plenty of time for updating. |
Sorry I wasn't clear. May be it is a specific case and does not need a major bump but here is an example. If the tsc compiler is generating definition files then after the upgrade the compiler generates files with |
I'm afraid all type definition changes are potentially breaking - there is no semver. Details here: https://blog.johnnyreilly.com/2018/09/ivan-drago-and-definitely-typed.html |
Due to the deprecation of the Stateless function component. ref: DefinitelyTyped/DefinitelyTyped#30364
📖Update to use FC and not SFC DefinitelyTyped/DefinitelyTyped#30364 By @Pau1fitz: * Initial work By @piotrwitek * rebase on master * Refactored all references related to SFC, stateless & stateful in favour of function and class components * Other minor improvements
* 📖Update to use FC and not SFC DefinitelyTyped/DefinitelyTyped#30364 * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Refactored all previous references related to SFC, stateless & stateful in favour of function and class components Other minor improvements
* chore: upgrade react dependencies * chore: replace ReactDOM.render with createRoot in index.ts * chore: fix new TS errors after upgrading @types * chore: replace ReactDOM.render in Preview.tsx * chore: replace ReactDOM.unmountComponentAtNode with root.unmount() * chore: remove ReactDOM import * chore: upgrade react testing library * chore: replace deprecated React.SFC type with React.FC DefinitelyTyped/DefinitelyTyped#30364 * chore: Fix TS errors in propTypes.children propTypes.node results in TS errors. There doesn't seem to be a good alternative ( other than making the children propTypes more strict, which could result more errors) Instead use something less restrictive (propTypes.any) for children and components. * chore: fix TS errors, extract props interfaces with children * chore: fix TS errors, add context types * chore: TS fix * fix: Fix React unmount error Unmount asynchronously with setTimout https://stackoverflow.com/questions/73459382/react-18-async-way-to-unmount-root error message: Warning: Attempted to synchronously unmount a root while React was already rendering. React cannot finish unmounting the root until the current render has completed, which may lead to a race condition. * test: make wrapper unmount test async --------- Co-authored-by: Thomas Roest <thomas.roest@moxio.com>
Upgrade to React 18 * replace ReactDOM.render with createRoot in index.ts * fix new TS errors after upgrading @types * replace ReactDOM.render in Preview.tsx * replace ReactDOM.unmountComponentAtNode with root.unmount() * remove ReactDOM import * upgrade react testing library * replace deprecated React.SFC type with React.FC DefinitelyTyped/DefinitelyTyped#30364 * Fix TS errors in propTypes.children propTypes.node results in TS errors. There doesn't seem to be a good alternative ( other than making the children propTypes more strict, which could result more errors) Instead use something less restrictive (propTypes.any) for children and components. * fix TS errors, extract props interfaces with children * fix TS errors, add context types * TS fix * Fix React unmount error Unmount asynchronously with setTimout https://stackoverflow.com/questions/73459382/react-18-async-way-to-unmount-root error message: Warning: Attempted to synchronously unmount a root while React was already rendering. React cannot finish unmounting the root until the current render has completed, which may lead to a race condition. * make wrapper unmount test async --------- Co-authored-by: Thomas Roest <thomas.roest@moxio.com>
📖Update to use FC and not SFC DefinitelyTyped/DefinitelyTyped#30364 By @Pau1fitz: * Initial work By @piotrwitek * rebase on master * Refactored all references related to SFC, stateless & stateful in favour of function and class components * Other minor improvements
* 📖Update to use FC and not SFC DefinitelyTyped/DefinitelyTyped#30364 * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Refactored all previous references related to SFC, stateless & stateful in favour of function and class components Other minor improvements
Use the term "function" instead of "functional" when referring to React function components. When hooks were introduced, SFC (Stateless Functional Component) was dropped in favor of FC (Function Component). With hooks, function components are no longer restricted to being stateless. The term "function" was adopted instead of "functional" since the latter implies Functional Programming paradigms such as pure functions, which is not a requirement of a function component. https://twitter.com/dan_abramov/status/1057625147216220162 DefinitelyTyped/DefinitelyTyped#30364
📖Update to use FC and not SFC DefinitelyTyped/DefinitelyTyped#30364 By @Pau1fitz: * Initial work By @piotrwitek * rebase on master * Refactored all references related to SFC, stateless & stateful in favour of function and class components * Other minor improvements
* 📖Update to use FC and not SFC DefinitelyTyped/DefinitelyTyped#30364 * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Refactored all previous references related to SFC, stateless & stateful in favour of function and class components Other minor improvements
Note: I'm reopening this as a new PR since #30188 was automatically closed while waiting for fixes to other React tests to merge.
This PR renames
React.SFC
andReact.StatelessComponent
toReact.FunctionComponent
, while introducing deprecated aliases for the old names. The motivation for this is twofold: firstly the addition of hooks means function components can have state, and secondly the term "stateless component" can equally apply to class components which don't use any state, causing some confusion.npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).If changing an existing definition:
The hooks docs at https://reactjs.org/docs/hooks-state.html#hooks-and-function-components
Dan Abramov's tweet on the subject https://twitter.com/dan_abramov/status/1057625147216220162
tslint.json
containing{ "extends": "dtslint/dt.json" }
.