Answer the question
In order to leave comments, you need to log in
What is the difference between FC, Styled, Class components in React?
Hello.
What is the difference between FC(func component), lFC(lambdaFC), Styled(styled``), Class-base(class ext React.C) components in React?
I create components in different ways and then output to the console:
Method 1 (lambdaFC):
const lFC = ()=>{
return (
<div>I'm lFC</div>
)
}
lFC = () => {
return React.createElement(
'div',
null,
'I\'m lFC'
);
}
function FC(){
return(
<div>I'm FC</div>
)
}
FC = ƒ FC() {
return React.createElement(
'div',
null,
'I\'m FC'
);
}
class CC extends React.Component {
componentDidMount(){
alert(hi)
}
render() {
return (
<div>I'm CC</div>
)
}
}
CC = class CC extends React.Component {
componentDidMount() {
alert(hi);
}
render() {
return React.createElement(
'div',
null,
'I\'m CC'
);
}
}
STYLED =
> {$$typeof: Symbol(react.forward_ref), render: ƒ, attrs: Array(0), componentStyle: ComponentStyle, displayName: "comp__StyledDiv", …}
Answer the question
In order to leave comments, you need to log in
You made a pointless comparison. All that can be learned from this method is that component instances are created by calling React.createElement. But it's in the documentation.
Class components have lifecycle methods, state, and the ability to work with context. Functional components achieve similar functionality using the Hooks API.
Using StyledComponent in functional components is not overhead. They are just wrappers for your components. In the console, you see the result of calling React.forwardRef. The call is needed in order to pass the ref to the wrapped component as a property, otherwise, when you try to get the ref, you would get a wrapper component.
The most simple applications are usually Todo sheets and other HelloWorldApp. In reality, the application will most likely be much more complicated.
FLUX is not exactly MVC.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question