7 January 2020

Arrow Function in React JS

  • Create Components folder under src folder
  • Add ArrowFunctions.js file and add below Code
import React, { Component } from "react";

class ArrowFunctions extends Component {
constructor(props) {
super(props);
this.state = {
Name: "Adi"
};
}
changeName = () => {
this.setState({ Name: "Adi JC" });
};

render() {
return (
<div>
Arrow Functions
<p>{this.state.Name}</p>
<button onClick={this.changeName}>Click me</button>
</div>
);
}
}
export default ArrowFunctions;
  • Open index.js file and update code as below
import React from "react";
import ReactDOM from "react-dom";

import "./styles.css";
import ArrowFunctions from "./Components/ArrowFunctions";

function App() {
return (
<div className="App">
<ArrowFunctions />
</div>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);


Output:


3 comments:

  1. Nice Blog.
    I've gone through all the details that you mentioned regarding arrow function in the blog along with the sample codes you mentioned for every small and big changes. I believe that every newbie could also understand the concept of using react native after going through this blog.
    I was looking forward to hire dedicated react native developer and got your blog.
    Thanks for sharing such a great blog.
    Synsoft Global

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete