Gathering detailed insights and metrics for react-clientside-effect
Gathering detailed insights and metrics for react-clientside-effect
Create components whose nested prop changes map to a global side effect
npm install react-clientside-effect
Typescript
Module System
Node Version
NPM Version
97
Supply Chain
99.5
Quality
79.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
444,796,562
Last Day
344,266
Last Week
1,461,886
Last Month
6,533,635
Last Year
90,139,420
100 Commits
4 Forks
3 Watching
3 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.2.7
Package Id
react-clientside-effect@1.2.7
Unpacked Size
16.28 kB
Size
4.73 kB
File Count
7
NPM Version
8.19.4
Node Version
16.20.2
Publised On
15 Dec 2024
Cumulative downloads
Total Downloads
Last day
-0.9%
344,266
Compared to previous day
Last week
-15.6%
1,461,886
Compared to previous week
Last month
4.5%
6,533,635
Compared to previous month
Last year
0.1%
90,139,420
Compared to previous year
1
1
27
Create components whose prop changes map to a global side effect.
This is client-side variation of the original react-side-effect, for client-side components. It does nothing on server side.
npm install --save react-clientside-effect
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);
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.
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
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 7/23 approved changesets -- score normalized to 3
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
59 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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