score:4
beside the differences you've already pointed out (lexical scope), arrow functions (and function expressions) are not hoisted, and as such cannot be called before they are defined. see my example. this is in my opinion not a problem, since code that relies on hoisting is much harder to reason about.
react really doesn't care about which one you use (nor can it detect it).
const a = () => {
const name = getname();
function getname() {
return 'praffn';
}
// will not work
// const getname = () => 'praffn';
return <p>hi, {name}</p>;
}
reactdom.render(<a/>, document.getelementbyid('root'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="root"></div>
score:4
since you are not accessing the this
context, both will both behave the same.
to understand more, you can check how babel is transpiring to the ecma:
const handleclick2 = () => {
console.log('handleclick2 executed...');
this.x=3
}
will be transpiled as:
"use strict";
var _this = void 0;
var handleclick2 = function handleclick2() {
console.log('handleclick2 executed...');
_this.x = 3;
};
Source: stackoverflow.com
Related Query
- What is the difference between arrow functions and regular functions inside React functional components (no longer using class components)?
- What is the difference between React Native and React?
- What is the difference between NextJs and Create React App
- What is the difference between hashHistory and browserHistory in react router?
- React Native - What is the difference between StyleSheet.absoluteFill() and StyleSheet.absoluteFillObject()?
- What is the main difference between React Query and Redux?
- React - What is the difference between renderToString and renderToStaticMarkup
- React Hooks: What is the difference between 'useMutationEffect' and 'useLayoutEffect'?
- What is the difference between React component instance property and state property?
- What is the difference between React component and React component instance?
- How does React router works and what is the difference between <link> and<Route>
- ES6 React - What are the difference between reference, shallow copy and deep copy and how to compare them?
- What is the difference between useHistory() and props.history in React Route
- what is the difference between getDefaultProps and getInitialState react js
- React Transition Group: What is the difference between the appear, enter, exit events and the enter, active done className suffixes?
- What is the difference between accessible, accessibilityLabel and accessibilityHint properties of Text component in react native?
- What is the real difference between value and defaultValue in React JS?
- What is the difference between a javascript package, node package, and react package?
- What is the difference between React and Preact diff algorithm in depth
- Difference between React Custom Hooks and Regular Functions
- What is the difference between a fibre object in React 16 and a React Element?
- What is the difference between Routing in React and Express
- What is the difference between these two functions 'foo1' and 'foo2'?
- What is the difference between passing a function name in onclick react and calling it through callback
- Difference between Regular javascript functions and React Functions
- What is the difference between key and id in React component?
- what is the difference between React setState and Hooks setState?
- what is the difference between element attribute and component attribute in React <Route><Route/> tag
- What is the difference between function and functional React component?
- What is the difference between Nav.Link vs Link vs NavLink in react router DOM and react bootstrap?
More Query from same tag
- How do I get value of an element after clicking another?
- Render list value updated by react hook
- change the sorter icon in ant design table component
- How do i resolve the react-router v6 Link element error?
- React-Redux: Access dispatch type in JSX
- React - Call parent method from within child component
- React - Render dynamic list of components
- ReactJS parent/child list items not rendering properly after an item is removed
- What condition should be applyed to child component in order to render conditionally
- What are the pros and cons of using a single action to modify multiple values, or an action for each value? Why?
- How to extend a component to add default props in React/TS
- reactjs MUI override style with parent reference
- How can i get access to the current user inside of react from firebase?
- Network graph using d3.js
- Debounce doesn't trigger function
- How do I install all the requirements with npm?
- Get current value of Animated.Value, React-native
- Make checkbox field mandatory using React
- How to configure Prettier to format Styled Components conditional rendering
- NodeJS: Download multiple files from GridFS and provide zip to the user on a button click
- How to handle images in a Rails / Webpacker / React app?
- showing error message returned from server validation in react
- render image on button click in react
- Loading different CSS based on deployment
- .map is undefined when mapping through the profile.education array
- React accessing a parent method from generated children components
- React.js: How to determine the correct link?
- Why do I get 'Cannot read property 'props' of undefined'?
- Formik Element type is invalid
- How to make GET request to API continuously?