Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jhta/react-use-theme

React Hook for consume styled component `theme`
https://github.com/jhta/react-use-theme

hooks react styled-components styled-system

Last synced: 8 days ago
JSON representation

React Hook for consume styled component `theme`

Awesome Lists containing this project

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 (



)
}

// 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 (


Hello World

)

}

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

````