How to create a button component in React

How to create a button component in React

In this post we will give you information about How to create a button component in React. Hear we will give you detail about How to create a button component in ReactAnd how to use it also give you demo for it if it is necessary.

This example will show you, how to create a reusable button component in react.

Button.js
import React from "react";function Button(props) {  return <button onClick={props.click}>{props.name}</button>;}export default Button;

Using the button component

We can use our button component anywhere in our react app like this.

App.js
import React, { Component } from "react";import Button from "./Button.js";class App extends Component {  state = {    name: "king"  };  changeName = () => {    this.setState({      name: "queen"    });  };  render() {    return (      <div>        <h1>{name}</h1>        <Button name="Change Name" click={this.changeName} />      </div>    );  }}export default App;

Hope this code and post will helped you for implement How to create a button component in React. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US