# react-use-theme

> React Hook for use styled components theme

Latest version **1.0.2** (published 2019-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-theme
pnpm add react-use-theme
yarn add react-use-theme
bun add react-use-theme
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-02-11 |
| First published | 2019-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jeison Higuita |
| Maintainers | jhta |
| Keywords | react, hooks, styled-components, theme |

## Links

- npm: https://www.npmjs.com/package/react-use-theme
- Repository: https://github.com/jhta/react-use-theme
- Homepage: https://github.com/jhta/react-use-theme#readme
- Issues: https://github.com/jhta/react-use-theme/issues
- npm.io page: https://npm.io/package/react-use-theme

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.8.1
- [styled-components](https://npm.io/package/styled-components.md) ^4.1.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-02-11
- 1.0.1 — 2019-02-11
- 1.0.0 — 2019-02-11

## README

# react-use-theme
React Hook for consume Styled Component `theme`

## Install

`yarn add react-use-theme`

## How to use it? 

Get any attribute from theme in React Components

````jsx
  const myColor = useTheme('colors.myColor')

````
Example

````jsx

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

const theme = {
  colors: {
    myCustomColor: '#07c'
  }
}

// You have to provide a Context theme
const App = () => {
  return (
    <ThemeProvider theme={theme}>
        <MyComponent />
    </ThemeProvider>
  )
}

// then you can access to theme with useTheme hook
const MyComponent = () => {
  const titleColor = useTheme('colors.myCustomColor')
  
  // you can pass default values
  const defaultColor = 'red'
  const subtitleColor = useTheme('colors.anotherColor', defaultColor)
  
  return (
    <div>
      <Title color={titleColor}>Hello World</Title>
    </div>
  )

}

const Title = styled.h1`
  color: ${p => p.color};
`


````

---
_Source: https://npm.io/package/react-use-theme · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
