Gathering detailed insights and metrics for react-side-effect
Gathering detailed insights and metrics for react-side-effect
Gathering detailed insights and metrics for react-side-effect
Gathering detailed insights and metrics for react-side-effect
react-clientside-effect
Create components whose prop changes map to a global side effect
use-isomorphic-layout-effect
A React helper hook for scheduling a layout effect with a fallback to a regular effect for environments where layout effects should not be used (such as server-side rendering).
@types/react-side-effect
TypeScript definitions for react-side-effect
@airma/react-effect
This is a react async state management tool
Create components whose nested prop changes map to a global side effect
npm install react-side-effect
Typescript
Module System
Node Version
NPM Version
98.3
Supply Chain
99
Quality
78.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
531,013,492
Last Day
414,888
Last Week
2,198,373
Last Month
9,383,333
Last Year
99,626,008
MIT License
1,222 Stars
112 Commits
77 Forks
14 Watchers
9 Branches
16 Contributors
Updated on May 05, 2025
Minified
Minified + Gzipped
Latest Version
2.1.2
Package Id
react-side-effect@2.1.2
Unpacked Size
20.13 kB
Size
5.29 kB
File Count
7
NPM Version
8.3.1
Node Version
16.14.0
Cumulative downloads
Total Downloads
Last Day
50.8%
414,888
Compared to previous day
Last Week
6.1%
2,198,373
Compared to previous week
Last Month
-3.3%
9,383,333
Compared to previous month
Last Year
5.4%
99,626,008
Compared to previous year
1
23
Create components whose prop changes map to a global side effect.
npm install --save react-side-effect
1<script src="https://unpkg.com/react/umd/react.development.js" type="text/javascript"></script> 2<script src="https://unpkg.com/react-side-effect/lib/index.umd.js" type="text/javascript"></script>
1<script src="https://unpkg.com/react/umd/react.production.min.js" type="text/javascript"></script> 2<script src="https://unpkg.com/react-side-effect/lib/index.umd.min.js" type="text/javascript"></script>
document.body.style.margin
or background color depending on current screen;componentDidUpdate
?It gathers current props across the whole tree before passing them to side effect. For example, this allows you to create <BodyStyle style>
component like this:
1// RootComponent.js 2return ( 3 <BodyStyle style={{ backgroundColor: 'red' }}> 4 {this.state.something ? <SomeComponent /> : <OtherComponent />} 5 </BodyStyle> 6); 7 8// SomeComponent.js 9return ( 10 <BodyStyle style={{ backgroundColor: this.state.color }}> 11 <div>Choose color: <input valueLink={this.linkState('color')} /></div> 12 </BodyStyle> 13);
and let the effect handler merge style
from different level of nesting with innermost winning:
1import { Component, Children } from 'react'; 2import PropTypes from 'prop-types'; 3import withSideEffect from 'react-side-effect'; 4 5class BodyStyle extends Component { 6 render() { 7 return Children.only(this.props.children); 8 } 9} 10 11BodyStyle.propTypes = { 12 style: PropTypes.object.isRequired 13}; 14 15function reducePropsToState(propsList) { 16 var style = {}; 17 propsList.forEach(function (props) { 18 Object.assign(style, props.style); 19 }); 20 return style; 21} 22 23function handleStateChangeOnClient(style) { 24 Object.assign(document.body.style, style); 25} 26 27export default withSideEffect( 28 reducePropsToState, 29 handleStateChangeOnClient 30)(BodyStyle);
On the server, you’ll be able to call BodyStyle.peek()
to get the current state, and BodyStyle.rewind()
to reset for each next request. The handleStateChangeOnClient
will only be called on the client.
withSideEffect: (reducePropsToState, handleStateChangeOnClient, [mapStateOnServer]) -> ReactComponent -> ReactComponent
A higher-order component that, when mounting, unmounting or receiving new props, calls reducePropsToState
with props
of each mounted instance. It is up to you to return some state aggregated from these props.
On the client, every time the returned component is (un)mounted or its props change, reducePropsToState
will be called, and the recalculated state will be passed to handleStateChangeOnClient
where you may use it to trigger a side effect.
On the server, handleStateChangeOnClient
will not be called. You will still be able to call the static rewind()
method on the returned component class to retrieve the current state after a renderToString()
call. If you forget to call rewind()
right after renderToString()
, the internal instance stack will keep growing, resulting in a memory leak and incorrect information. You must call rewind()
after every renderToString()
call on the server.
For testing, you may use a static peek()
method available on the returned component. It lets you get the current state without resetting the mounted instance stack. Don’t use it for anything other than testing.
Here's how to implement React Document Title (both client and server side) using React Side Effect:
1import React, { Children, Component } from 'react'; 2import PropTypes from 'prop-types'; 3import withSideEffect from 'react-side-effect'; 4 5class DocumentTitle extends Component { 6 render() { 7 if (this.props.children) { 8 return Children.only(this.props.children); 9 } else { 10 return null; 11 } 12 } 13} 14 15DocumentTitle.propTypes = { 16 title: PropTypes.string.isRequired 17}; 18 19function reducePropsToState(propsList) { 20 var innermostProps = propsList[propsList.length - 1]; 21 if (innermostProps) { 22 return innermostProps.title; 23 } 24} 25 26function handleStateChangeOnClient(title) { 27 document.title = title || ''; 28} 29 30export default withSideEffect( 31 reducePropsToState, 32 handleStateChangeOnClient 33)(DocumentTitle);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 7/12 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
46 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More