I use to declare stateless components like this:
const example: React.SFC<IExample> = ({propsType}) => ();
However the SFC is now deprecated, maybe this twitter post from Dan Abramov explains why.
What should we use now that SFC is deprecated?
From the sounds of things, it will eventually be deprecated in favor of the naming React. FunctionComponent once React 18 is released.
The SFC (short for stateless functional component) defines a function type that returns a JSX Element. Use the React.ReactChild return type if you want to allow other renderable elements, like strings or numbers. // This is not allowed const MyComponent: React.
May 2021 edit: the Remix framework from the React Router duo also adopt a single file component format that involves exporting links , loader , and action . The launch of RedwoodJS today marks a first: it is the first time React components are being expressed in a single file format with explicit conventions.
A functional(a.k.a. stateless) component is just a plain javascript function which takes props as an argument and returns a react element. const MyStatelessComponent = props => React. createElement('div', null, props.name);
You should use React.FunctionComponent
: Rename React's SFC to 'FunctionalComponent
This PR renames
React.SFC
andReact.StatelessComponent
toReact.FunctionComponent
, while introducing deprecated aliases for the old names.
So your example would become:
const example: React.FunctionComponent<IExample> = ({propsType}) => ();
or
const example: React.FC<IExample> = ({propsType}) => ();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With