
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
direct-styled
Advanced tools
Very tiny (2kb) lib built with Typescript containing a HOC and a hook which enables you to set rapid changing styles without causing React-re-render.
Very tiny (2kb) lib built with Typescript containing a HOC and a hook which enables you to set rapid changing styles without causing React-re-render.
Read my blog post for more background regarding the how's and why's.
Advice: Try to update styles with normal React state first! React is very fast, and most of the time React.useState
will suffice.
import * as React from "react";
import { directstyled, useDirectStyle } from "direct-styled";
function Example() {
const [style, setStyle] = useDirectStyle();
return (
<directstyled.div
style={style}
onMouseMove={evt =>
setStyle({
transform: `translate(${evt.clientX}px, ${evt.clientY}px)`
})
}
/>
);
}
Checkout a working demo on CodeSandbox!
npm install --save direct-styled
or
yarn add direct-styled
Just another HOC. Without the special style provided by useDirectStyle
, no additional behavior is added.
import { directstyled } from "direct-styled";
// use with shorthand
const x = <directstyled.div />;
// ...or
const x = <directstyled.article />;
// construct with a tag-name
const x = directstyled("div");
// construct with a component
const x = directstyled(MyButton);
// or with styled-components
const x = directstyled(styled.div``);
import { useDirectStyle } from "direct-styled";
function Example() {
// pass `style` to a directstyled-component
// use `setStyle` to react to series of rapid changes, ie. mouse and scroll events
const [style, setStyle] = useDirectStyle();
return (
<div
onMouseMove={evt =>
// Set new css-transform values, unburden the work of React
setStyle({
transform: `translate(${evt.clientX}px, ${evt.clientY}px)`
})
}
>
{/* Multiple directstyled-components can share the same `style` */}
<directstyled.div
style={{ position: "absolute", top: 0, left: 0, ...style }}
/>
/* Multiple directstyled-components can share the same `style` */}
<directstyled.div
style={{ position: "absolute", top: 50, left: 50, ...style }}
/>
</div>
);
}
MIT © everweij
FAQs
Very tiny (2kb) lib built with Typescript containing a HOC and a hook which enables you to set rapid changing styles without causing React-re-render.
The npm package direct-styled receives a total of 330 weekly downloads. As such, direct-styled popularity was classified as not popular.
We found that direct-styled demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.