From cbd056ffbfa186c22c8158699093d8987b55862d Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Mon, 18 Mar 2024 18:18:08 -0700 Subject: [PATCH] [flow][website] Remove outdated recommendation Summary: With namespaces work, this is no longer necessary. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D55046747 fbshipit-source-id: 634494829541c2da6354632ac1739f4a8b91e50c --- .../docs/react/function-and-class-components.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/website/docs/react/function-and-class-components.md b/website/docs/react/function-and-class-components.md index 3e8b29aa9db..13392b802ad 100644 --- a/website/docs/react/function-and-class-components.md +++ b/website/docs/react/function-and-class-components.md @@ -13,7 +13,7 @@ Adding Flow types to a functional component is the same as [adding types to a st Just create an object type for the props and Flow will ensure that the props passed to the component match up with what is expected. ```js flow-check -import * as React from 'react'; +import React from 'react'; type Props = { foo: number, @@ -29,12 +29,6 @@ function MyComponent(props: Props) { ``` -> **Note:** We import `React` as a namespace here with -> `import * as React from 'react'` instead of as a default with -> `import React from 'react'`. When importing React as an ES module you may use -> either style, but importing as a namespace gives you access to React's -> [utility types](../types). - ### Adding Default Props to Functional Components {#toc-adding-default-props-to-functional-components} @@ -44,7 +38,7 @@ By destructuring the props in the function parameter, you can assign a value to to the component (or passed with the value `undefined`). ```js flow-check -import * as React from 'react'; +import React from 'react'; type Props = { foo?: number, // foo is optional to pass in. @@ -67,7 +61,7 @@ argument to the `React.Component` type. This will have the same effect as adding to the `props` parameter of a function component. ```js flow-check -import * as React from 'react'; +import React from 'react'; type Props = { foo: number, @@ -103,7 +97,7 @@ type, in the example below we name it `State`, and pass it as the second type argument to `React.Component`. ```js flow-check -import * as React from 'react'; +import React from 'react'; type Props = { /* ... */ }; @@ -147,7 +141,7 @@ value from `defaultProps`. Flow supports this notion as well. To type default props add a `static defaultProps` property to your class. ```js flow-check -import * as React from 'react'; +import React from 'react'; type Props = { foo: number, // foo is required.