score:0
in the function buttontwobackgroundcolor you set setbuttontwo to a object. it should be a string.
const buttontwobackgroundcolor = () => {
setbuttontwo("red")
}
score:0
you are trying to set state to be an object when you have defined the defualt state as a string.
update the default state to an object and then access properties like this:
import react, { usestate } from "react";
import { button } from "antd";
import "./styles.css";
export default function app() {
const [buttonone, setbuttonone] = usestate("red");
const [buttontwo, setbuttontwo] = usestate({backgroundcolor: "blue", border: "blue"});
const buttontwobackgroundcolor = () => {
setbuttontwo(prevstate => ({
...prevstate,
backgroundcolor: 'blue',
border: 'red'
}));
};
return (
<div>
<button
style={{ backgroundcolor: buttonone, border: buttonone }}
classname="one"
type="primary"
>
first
</button>
<button
style={{ backgroundcolor: buttontwo.backgroundcolor, border: buttontwo.border }}
onclick={buttontwobackgroundcolor}
classname="two"
type="primary"
>
second
</button>
</div>
);
}
score:0
change
onclick={buttontwobackgroundcolor}
to
onclick={setbuttontwo("red")}
you are using usestate as string at initialization and assigning an object in function below, which is not proper way!
Source: stackoverflow.com
Related Query
- how to change background color when I click the button using react hooks
- How to change button background color when I click the button in React using Hooks
- How to change the background and text color within button using button onClick in React JS
- Use click handler to change color of button when there are multiple buttons using the same function
- How to change background color of button using react
- how to change the background color of a button without affecting the other buttons in React JS
- How Do I make my Nav Menu option change color or background when I click on it using Javascript only?
- How to change the default screen background color of all the pages in React JS(Next JS) using tailwind CSS
- How do I target and change the style of a different element when I click a button in react
- How to change the background color of th on click in react js?
- How to hide a button when I click the button in react using functional components
- How to change button color when pressed in React Native using TouchableHighlight?
- How to change the menu item's color of sidebar when we click on it with css in React pls
- When I click the button, I want to change the page background color to another color, not black, how can I do it?
- how do you single select change the value when the radio button is checked, using react hooks?
- How to change the style of a button when it is clicked in react using css?
- How to change background color of react native button
- How to change the color of a active button only in react native
- randomly change the background color of a react app by a click
- How to change the selected table row background color with React
- How to change the selected table row background using Material-UI on React
- How to make one table record editable on button click in React when the table record is mapped?
- React - How to change code written in the old way when using a new approach?
- how to change the font color, font size, and button color in React
- How to add a tab dynamically when we click a button using React js and Bootsrap 4
- How to get the time in seconds after click on submit button using React Count Down Timer
- How to change navbar background color in react when I scroll
- How to change the state value using a click button
- React Js how to jump whole pages to other pages when click on the navigation button
- How do you change the color of a React component using props
More Query from same tag
- How solved the sintax to concat an element HTML?
- I need to re render state and make onChange operator work on input element
- Problems with the use of loop in JSX
- React Hook for re-rendering state updated by asynchronous recursive function
- Cannot read property 'X' of undefined - React-bootstrap
- Using React Router the <Redirect /> Does not redirect anywhere, but why?
- set function does not trigger an update in React with Recoil
- Dom contains or compareDocumentPosition analog in react
- Transform is not triggered again on window resize
- Getting TypeError: _react.default.memo is not a function only when I use FavoriteIcon in my app
- Fetching multiple GET requests API using React and assigning variables
- React Jquery Datatable
- Electron: Pasting a string using the context menu
- React useEffect returns empty array after fetching data with axios
- How to pass props into component from react-router Switch statement
- Map or/and filter to select elements in React
- Building up an array before submission
- React: How to prevent menu component from being remounted when switching pages
- How to add items to localstorage in react?
- "vh" and "vw" not relative to screen height
- React: How to pass the data from function located on the child component into parent component?
- Deploying Create-React-App with Rails API on Heroku
- What type should I use instead of any?
- how to wrap React-router with context provider
- React.js .map is not a function, mapping Firebase result
- React data after .Map
- Can't resolve 'material-ui/Button'
- How to access property with a condition inside React.useState() and change it
- ant-design select not styled properly
- Sass-loader with Webpack, React and Babel not working