Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created January 26, 2020 11:04
Show Gist options
  • Save manojnaidu619/2c8051ed9eb538983eff47578a03446f to your computer and use it in GitHub Desktop.
Save manojnaidu619/2c8051ed9eb538983eff47578a03446f to your computer and use it in GitHub Desktop.
React functional component(Uses hooks for state management)
import React, {useState} from 'react';
const App = props => {
const [pstate, sstate] = useState({
name: "Manoj",
country: "India"
})
const switchNameHandler = () => {
sstate({
name: "Arun",
country: "Japan"
})
}
return(
<div className="App">
<h1>Hello</h1>
<button onClick={switchNameHandler}>Click Here</button>
<p>{pstate.name}</p>
<p>{pstate.country}</p>
<Person name="manoj"/>
</div>
)
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment