score:1
Accepted answer
in this case you could use useref
:
const [active, setactive] = usestate(false)
const moderef = useref();
const handletoggle = () => {
moderef.current.classlist.toggle("dark")
}
return (
<button ref={moderef} classname="mode-switch" title="switch theme" onclick={handletoggle}>
<svg classname="moon" fill="none" stroke="currentcolor" strokelinecap="round" strokelinejoin="round" strokewidth="2" width="24" height="24" viewbox="0 0 24 24">
<defs></defs>
<path d="m21 12.79a9 9 0 1111.21 3 7 7 0 0021 12.79z"></path>
</svg>
</button>
)
Source: stackoverflow.com
Related Query
- how to toggle between two css classes with react
- how to toggle between two css classes view types with react
- How to toggle CSS class between buttons rendered with .map()
- How to toggle CSS styles with Toggle method in React
- how to toggle a className between two list items in react
- How to toggle css class in react with setState Hook
- How to toggle between two buttons in React and chnange the NAvlink path based on button clicked
- how do i toggle disabled between two buttons in react map
- How to apply global styles with CSS modules in a react app?
- How to import CSS modules with Typescript, React and Webpack
- How to make a shared state between two react components?
- How to CSS display:none within conditional with React JSX?
- How to conditionally apply CSS classes in React JS
- How to create two columns with space beetwen in react native - flatList
- Line two divs side by side with CSS and React
- How to style child components in React with CSS Modules
- How to communicate UI state changes between React components with Redux?
- How to use vw and vh css with React Native
- How to maintain state between routes with React Router?
- Communication between two React form components with Redux
- How do you use CSS grid layouts with React effectively?
- Share the same styles between two types of component with React Styled Components
- how to deal with css imports for react server-side render
- How to do autosuggest css keywords with React Codemirror?
- How can I pass CSS classes to React children and ensure they will override the child’s local class?
- How to conditionally apply styles in a react component with CSS Modules?
- How to write if condition with two statement in React Native
- Add & Remove CSS classes with React
- How to toggle css class of a single element in a .map() function in React
- How to use inheritance with React components and es6 classes
More Query from same tag
- Splitting ReactJS onto multiple assemblies
- How to focus an element only if it isn't currently focused?
- Change from viewing analogue clock to digital clock in React
- sibling selector with :before doesn't work in styled-component?
- React useState, value of input doesnt update
- Render data from localStorage with react
- React redux proper updating record and reflecting changes on the screen
- Global variable for react
- ReactJS Form Submission
- How to use AND and OR statement inside the component while comparing in react component
- Combining text and JS in className after a ternary operator
- Components Library - Show Index
- Using hooks from a nested componentDidMount()
- TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics is not a function
- Using React Burger Menu with GatsbyJs
- How to mock a method which returns response object using Jest
- React + React-router -> Child routes best organization?
- React, Typescript, Hooks - Property 'state' does not exist on type
- How can I change the label size of a material ui TextField?
- React loop through children without ref
- How to write a recompose HOC to User Analytics?
- Refactor nested async callback within react’s componentDidMount() using an external file
- UseEffect or throwing logic in the functional component
- basic question related to increment and decrement the counter in react
- Uncaught Error: Could not find "store" in either the context or props of Connect(Form())
- react-grid-layout Error: <DraggableCore> not mounted on DragStart
- In React ES6, is there any benefit to using an imported component that contains only one element tag with a class?
- ReactJS - cannot read this.props.value on state object
- React TypeError: Cannot read property '0' of undefined
- Uncaught TypeError: Cannot read properties of undefined (reading 'params') in a MERN Stack app