react-toggle-theme
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-toggle-theme

alt text

A simple component to switch between dark and light themes

Install

yarn add react-toggle-theme
npm install --save react-toggle-theme

Usage

import React from "react";
import ToggleTheme from "react-toggle-theme";
 
function App() {
  const [currentTheme, setCurrentTheme] = React.useState("light");
 
  React.useEffect(() => {
    console.log("Toggle theme");
    // Handle theme logic
    // e.g. update localstorage, set window.THEME = theme, etc.
  }, [currentTheme]);
 
  return (
    <div
      className={"app-container"}
      style={{ backgroundColor: currentTheme === "light" ? "#000" : "#fff" }}
    >
      <ToggleTheme selectedTheme={currentTheme} onChange={setCurrentTheme} />
    </div>
  );
}
 
export default App;

Readme

Keywords

Package Sidebar

Install

npm i react-toggle-theme

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

17.3 kB

Total Files

10

Last publish

Collaborators

  • forgng