0% found this document useful (0 votes)
50 views2 pages

React State and Props

The document contains two React component examples that demonstrate the use of state and props. The first component manages a user's name and displays it along with an ID and the current date, allowing the name to be changed via a button. The second component tracks a count value that can be incremented by clicking a button.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

React State and Props

The document contains two React component examples that demonstrate the use of state and props. The first component manages a user's name and displays it along with an ID and the current date, allowing the name to be changed via a button. The second component tracks a count value that can be incremented by clicking a button.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

React State and Props

import React, { Component } from 'react'


export default class App extends Component {
constructor(){
super()
[Link]={id: 1, name: "Sona", date: new Date()}
}
changeName =()=>{
[Link]({name: "Salem"})
}
render() {
return (
<div>
<h1>Id: {[Link]}</h1>
<h1>Name: {[Link]}</h1>
<h1>Date: {[Link]()}</h1>

<button onClick={[Link]}>Change Name</button>


</div>
)
}
}
import React, { Component } from 'react'
export default class App extends Component {
constructor(){
super()
[Link] ={count: 0}
}
increment = ()=>{
[Link]({count: [Link]+1})
}
render() {
return (
<div>
<h1>Count: {[Link]}</h1>
<button onClick={[Link]}>Increment</button>
</div>
)
}
}

You might also like