0.1.5 • Published 5 years ago

use-theme v0.1.5

Weekly downloads
4
License
MIT
Repository
-
Last release
5 years ago

Build Status

Install

# With NPM
$ npm install use-theme

# With Yarn
$ yarn add use-theme

Usage

import React, { useCallback } from 'react'
import { useTheme, ThemeProvider } from 'use-theme'

const ChangeThemeButton = ({ children, theme }) => {
  const [currentTheme, setTheme] = useTheme()
  const changeTheme = useCallback(() => setTheme(theme), [theme, setTheme])
  return (
    <button
      className={theme === currentTheme ? 'active' : ''}
      onClick={changeTheme}
    >
      {children}
    </button>
  )
}

const App = () => {
  const [theme, setTheme] = useTheme()
  return (
    <div className={theme}>
      <ChangeThemeButton theme="dark">Dark theme</ChangeThemeButton>
      <ChangeThemeButton theme="light">Light theme</ChangeThemeButton>
    </div>
  )
}

ReactDOM.render(
  <ThemeProvider>
    <App />
  </ThemeProvider>,
  document.getElementById('app')
)
0.2.0-alpha.1

5 years ago

0.2.0-alpha.0

5 years ago

0.1.5

5 years ago

0.1.5-alpha.0

5 years ago

0.1.4

5 years ago

0.1.4-alpha.2

5 years ago

0.1.4-alpha.1

5 years ago

0.1.4-alpha.0

5 years ago

0.1.3

5 years ago

0.1.2-alpha.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago