npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-strict-dom

v0.0.29

Published

React Strict DOM

Downloads

13,198

Readme

react-strict-dom

GitHub license npm version

web (prod) web (dev) native

React Strict DOM (RSD) standardizes the development of styled React components for web and native. The goal of RSD is to improve the speed and efficiency of React development without compromising on performance, reliability, or quality. Building with RSD is helping teams at Meta ship features faster, to more platforms, with fewer engineers.

Documentation

Please refer to the React Strict DOM website for detailed documentation. The API section includes detailed compatibility tables for native. Please read the linked issues for details on the most significant issues, and register your interest (e.g., thumbsup reaction) in supporting these features on native platforms.

Quick start

Install

npm install react react-strict-dom

For web:

npm install react-dom

For native:

npm install react-native

Example

Styles are passed to elements using the style prop. The style prop accepts an array of static and dynamic styles.

import { css, html } from 'react-strict-dom';

const styles = css.create({
  root: {
    marginBlock: '1rem'
  },
  cond: {
    borderWidth: '5px'
  },
  opacity: (value) => ({
    opacity: value
  })
})

export default function App(props) {
  const opacity = useOpacity();
  return (
    <html.div
      {...props}
      style={[
        styles.root,
        cond && styles.cond,
        styles.opacity(opacity)
      ]}
    />
  );
}

Other tips

Suppressing logs on React Native

RSD provides comprehensive runtime warnings and errors to inform developers of about prop and style incompatibilities on native. If there are certain logs that you wish to suppress, this can be done by configuring the React Native LogBox at the root of the native app. Messages follow a common structure, which allows for precise or general suppression. For example:

import { LogBox } from 'react-native';

LogBox.ignoreLogs([
  // Specific errors
  '[error] React Strict DOM: css.keyframes() is not supported',
  // Specific warnings
  '[warn] React Strict DOM: unsupported prop "onInvalid"',
  '[warn] React Strict DOM: unsupported style value in "display:inline-flex"',
  // All warnings of a certain kind
  /\[warn\] React Strict DOM: unsupported style property .*/,
  // All warnings
  /\[warn\] React Strict DOM: .*/,
  // All logs
  /\[log\] React Strict DOM: .*/,
]);

Ignore logs as a last resort and create a task to fix logs that are ignored.

Adding Flow types for data-* props

Flow does not currently support typing arbitrary data-* props (#71). The workaround is to use a Flow libdef to define the data-* props used by your apps (or dependencies) via the ReactStrictDOMDataProps type. For example:

// flow-typed/react-strict-dom.js
declare type ReactStrictDOMDataProps = {
  'data-imgperflogname'?: string,
  'data-impression-id'?: number,
};

This is a temporary solution until Flow provides a built-in approach to handling data-* prop types. DO NOT use this workaround to define any non-data-* props.

Adding Flow types for translation strings

Certain prop values are typically user-facing strings, and these are defined within RSD as being of type Stringish - just a string. But when Flow doesn't know that a translation function produces strings at runtime, you can override the type of Stringish to account for this. For example, if using Meta's internationalization framework Fbt:

// flow-typed/stringish.js
declare type Stringish = string | Fbt;

This is the same approach used by React Native, so if you are already re-declaring Stringish it will work out-of-the-box with RSD.

License

React Strict DOM is MIT licensed.