Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between React.FunctionComponent and React.SFC

What is the difference between React.FunctionComponent and React.SFC. I'm new To typescript, and actually I don't know when to use one over the other. for example when using react hooks should I use only React.FunctionComponent, because I use some sort of state inside my component.

like image 632
Abdellah El Mennani Avatar asked Feb 15 '19 10:02

Abdellah El Mennani


People also ask

What is SFC in React?

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.

Should you use React FunctionComponent?

FunctionComponent provides an implicit definition of children . This means that when you type your component with React. FC , the component automatically accepts children provided to your component. It will not throw any typescript error, but it actually should, because the children do nothing.

What is the difference between class based component and functional component?

Class ComponentsA functional component is just a plain JavaScript pure function that accepts props as an argument and returns a React element(JSX). A class component requires you to extend from React. Component and create a render function which returns a React element.

What is the difference between state and props?

Props are used to pass data from one component to another. The state is a local data storage that is local to the component only and cannot be passed to other components. The this. setState property is used to update the state values in the component.


1 Answers

React.SFC (which stands for stateless function component) is an alias for React.FunctionComponent.

It was deprecated because functional components aren't stateless since React 16.8.

like image 153
Estus Flask Avatar answered Oct 04 '22 17:10

Estus Flask