Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-css-variables

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-css-variables

A React HOC for CSS variables

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

react-css-variables

npm package

npm install --save react-css-variables

A React HOC for CSS variables

Provides a HOC to create a component with props mapped to CSS variables. It allows to update CSS of underlying components without any DOM operation.

The HOC won't trigger a render if only one of the variables is changed. This can be a huge performance improvement if you have a component with a deep render tree, since instead of passing props in elements as inline styles, you can only set variables, and no render will be triggered.

Usage

import styled from 'styled-components'
import variables from 'react-css-variables'

// We use styled-components, but it's totally up to you, as long as the css uses variables.
const Title = styled.h1`
  color: var(--color);
  background: var(--background);
`

// Wrap our component with provided HOC.
const VariablesTitle = variables('color', 'background')(Title)

// Changing "color" or "background" will not trigger a render.
const Demo = () => (
  <VariablesTitle color='red' background='blue'>
    Hello world
  </VariablesTitle>
)

Keywords

FAQs

Package last updated on 06 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc