score:0
for access to the value of the button, you can pass the value into the onClick method
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import './ui.css'
declare function require(path: string): any
class App extends React.Component {
state={currentValue:''}
cornerRadiusValues = [4, 8, 16, 24, 32, 40, 48];
cornerRadiusButtons = this.cornerRadiusValues.map((cornerRadiusValue, index) =>
<button key={index} value={cornerRadiusValue} id="cornerRadiusValue"
onClick={() => this.setAttibute(cornerRadiusValue)}>{cornerRadiusValue}</button>
);
setAttibute = (value) => {
this.setState({
...this.state,
currentValue:value
})
}
render() {
return <div>
{this.cornerRadiusButtons}
</div>
}
}
ReactDOM.render(<App />, document.getElementById('react-page'))
and you can access the value of state inside of component with this command
this.state.currentValue
Copy an object to another one
var firstObject = {
key1 : 'value1',
key2 : 'value2'
};
var secondObject = {
...firstObject,
key3 : 'value3',
key4 : 'value4'
};
Source: stackoverflow.com
Related Query
- How to use state to update the value of variable in the button value property?
- How do I use the spread operator to update a state value in React?
- React - How to use the current state value as a variable so i can set as a index inside an array
- How to change the value of a variable dynamically, change state and update UI
- How to ignore a property update of the state in ReactJs?
- Use useState value in useEffect without making the state update useEffect
- how update the value of useEffect() hook on button click
- How to update the correct state value in a parent component that gets its value from a child component using hooks in react?
- How to change the state value using a click button
- How to update specific value when the state is an array of objects - React
- How to use setState to update the property of an object inside an array the right way in class component?
- How to update redux state using a react variable passed up to the component from a child
- How to store the value of a variable in state immediately when set state is async
- how do i update state in react for updating the value of an object inside an array using array.map function
- How to update a single property of the state in a react hook?
- How to update state value of variable that uses custom Hook
- How do i change a property in state whose name is the value of a variable?
- In Reactjs how do I update the correct value in the parent state with a callback that's been passed to a nested child component?
- How to use mapStateToProps to get a value from the state based on a context value?
- How can i update context value with the state value
- How to update the value of a prop upon a state change in React
- How to update state in ReactJS and use the values at the same time
- How to disable a button when the state or the input value gets changed in React JS?
- How do I update the value of text when I hold an button
- State in Reactjs holding the previous state value, how to update the state with new edited form value
- React: How I can change a state variable based on the value of another state variable?
- React: Execute function in useEffect Hook to update state. Use the state value to return component A or B
- How to update a Textfield that has a value from an array of objects state variable in React?
- How do I use React setState() to set the state to a specific value that is a constant?
- how to update a children component when the value of state change
More Query from same tag
- Proxy in development mode of React won't redirect
- "Stripe is not defined" error - call of function before script is loaded?
- Why is my Reactjs app URI showing the a replacement for :
- reactnative IllegalViewOperationException: Unable to execute operation dispatchViewManagerCommand on view with tag: 1909 since the view does not exist
- React keys for list of integers
- What are the best alternatives for javascript clientWidth in reactjs?
- crop image in reactjs using html5 canvas
- How to test reducer with Immer/produce?
- Pass state from one component to another stateless component
- How to send data (from Reactjs) through a class based API (Django Rest Framework)
- Toggling the static key boolean in layout object of a react-grid-layout causes all grid items to move incorrectly
- Checkbox status does not change in react
- How to go to another domain/route when even happening in React (Router)
- React how to access state from a function in another file?
- Formik re-renders on react state change
- How do I mock react-router-dom using jest from a __mocks__ directory
- React native layout fixed width and stretch remaining space
- React/js onClick on both the Parent div and Child div. Parent always fires
- React Hooks - Changing state inside child does not reflect in parent
- React hooks - trigger useEffect when a nested property changes in a collection of objects
- How to create redux store within UseEffect, correct pattern?
- Syntax error when trying to fetch jwt key in Node.js and React
- Apply styles for each shape
- Passing data to another component does not working
- React hot loader not showing changes in the browser
- Prevent vscode jest extension interpreting cypress tests as jest tests
- Passing Props to Child component from Parent using cloneElement
- Extract frames from specific times from video
- How to add a form to meteor and react application
- Getting token (JWT) error in MERN stack task manager