Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/style-hook/style-hook

use css in js with react hook.
https://github.com/style-hook/style-hook

css css-hook react-hook react-hooks style-hook

Last synced: about 1 month ago
JSON representation

use css in js with react hook.

Awesome Lists containing this project

README

        

![logo](https://avatars1.githubusercontent.com/u/54980825?s=200&v=4)

# style-hook
easy to write dynamic css

[![Build Status](https://www.travis-ci.org/style-hook/style-hook.svg?branch=master)](https://www.travis-ci.org/style-hook/style-hook)
[![codecov](https://codecov.io/gh/style-hook/style-hook/branch/master/graph/badge.svg)](https://codecov.io/gh/style-hook/style-hook)

# features
* use css in react hook
* easy to get started

# install
use npm
```bash
npm i -S style-hook
```
or use yarn
```bash
yarn add style-hook
```

## minify css in js (recommend)
add babel plugin to your .babelrc
```json
{
"plugins": [
"style-hook/babel"
]
}
```

# usage
## say hello world to get started
``` jsx
import React from 'react'
import { useStyle } from 'style-hook'
export default function() {
const s = useStyle `
font-size: 30px;
margin: 20px;
color: red;
`
return

hello world

}
```

## a dynamic style example
all grammars are js, one you need to learn is js.
``` jsx
import React from 'react'
import { css, useStyle } from 'style-hook'
function HelloWorld(props) {
const cName = useStyle `
font-size: 30px;
width: ${100/3}%;
margin: ${props.margin || 10}px;
color: ${props.color};
:hover {
${props.hoverStyle}
}
`
return

hello world

}
export default () => {
const hoverStyle = css `color: red;`
return (

)
}
```

## more usages
see the wiki: [api](https://github.com/style-hook/style-hook/wiki/api) and [F&Q](https://github.com/style-hook/style-hook/wiki/F&Q)

# typescript
support by default

# Highlight and IntelliSense (recommend)
* [vscode extension](https://marketplace.visualstudio.com/items?itemName=coppy.style-hook)

# support me
if you like this project, star it, let more one know.

# Credits
* [styled-components](https://github.com/styled-components/styled-components)
* [stylis](https://github.com/thysultan/stylis.js)