Im learning react native and I have a question, im watching course from 2018 where teacher use Export default class, and in new tutorials i see that ppl use export default function, soo should i use class or function in my apps?
Asked
Active
Viewed 51 times
0
-
Does this answer your question? [Const vs Class Functions is React Native](https://stackoverflow.com/questions/57762163/const-vs-class-functions-is-react-native) – Vivek Mar 13 '20 at 12:50
-
also: https://stackoverflow.com/questions/36097965/when-to-use-es6-class-based-react-components-vs-functional-es6-react-components – Vivek Mar 13 '20 at 12:51
-
you can use the class system or the newer Hooks approach in React / react native - depends on your preference. – yesIamFaded Mar 13 '20 at 13:23
1 Answers
0
use accordingly, but hooks are easy way to implement in any project. The benefit that I could see is in Redux:-
It eliminates the use of connect function in class that is a higher order component
Using Class:=
const mapStateToProps = (state) => {
return {
test: test(state),
}
};
const mapDispatchToProps = dispatch => ({
test: () => dispatch(test),
});
Using Hooks:=
const test = `useSelector`(state => state.test); //similar to mapStateToProps
import { useDispatch } from 'react-redux;
const dispatch = useDispatch();
dispatch(test); //similar to mapDispatchToProps
Please comment if anyone find other advantages too.

Mohit
- 1
- 2