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
- React restClient admin-on-rest
- How to get ref value of button in function [react]
- How to render props conditionally and checking for undefined, while passing props via React useHistory?
- Applying State to Nested Object in React. How do I call API and display with Use Effect
- How to display a value in my title attribute
- Adding element to antd Dropdown overlay property results in React single child error
- How to create a react portal within ant-design dropdown overlay
- React Leaflet with grouped layers
- Warning.js?6327:33 Warning: Unknown prop `store` on <provider> tag
- Converting this class to a functional component
- 'ControllerBase.File(byte[], string)' is a method, which is not valid in the given context (CS0119) - in method
- How to pass function from statefull to stateless component?
- React app running in docker container being served with nginx is blank
- Access props outside class
- jQuery Trigger and On in JSFiddle
- import Excel from "exceljs" throwing error on browser TypeError: Cannot read property 'prototype' of undefined
- Why doesn't second (sibling) React Context Provider work? Or, why doesn't a React Context Provider work if there is a sibling Context Provider above
- React Redux how make conditional rendering with redux state
- React Redux cannot pass props of a functional component
- Re-render does not occur when state changes
- firebase web sign up with google only works after clicking the second time?
- Is there a way to avoid blanks in react loadable components
- Object is not getting rendered on screen
- Toggle components using reactjs
- React-Sidenav main content isn't styled
- Do you really need to import 'React' when creating hooks? (React-hooks)
- React - Render Objects with changing Props
- Material-UI ListItem "flex-start" not working
- Timer on each row of dynamic table
- Issue with react state not updating/incrementing