Create components whose nested prop changes map to a global side effect
Installations
npm install react-clientside-effect
Score
93.3
Supply Chain
98.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
thekashey
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
14.18.3
NPM Version
6.14.15
Statistics
94 Commits
3 Forks
3 Watching
3 Branches
1 Contributors
Updated on 06 May 2022
Bundle Size
1.63 kB
Minified
786.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
431,461,648
Last day
-8.3%
320,726
Compared to previous day
Last week
2.6%
1,810,720
Compared to previous week
Last month
5%
7,690,903
Compared to previous month
Last year
0.1%
90,526,526
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
Dev Dependencies
27
React Side Effect
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.
Installation
npm install --save react-clientside-effect
Use Cases
- Setting
document.body.style.margin
or background color depending on current screen; - Firing Flux actions using declarative API depending on current screen;
- Some crazy stuff I haven't thought about.
How's That Different from 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);
API
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.
Usage
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 5/25 approved changesets -- score normalized to 2
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Reason
58 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-832h-xg76-4gv6
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-p28h-cc7q-c4fg
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-2m96-9w4j-wgv7
- Warn: Project is vulnerable to: GHSA-h726-x36v-rx45
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2
/10
Last Scanned on 2024-11-18
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 MoreOther packages similar to react-clientside-effect
@radix-ui/react-use-layout-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).
react-side-effect
Create components whose prop changes map to a global side effect
@react-hook/passive-layout-effect
A React hook that uses useEffect() on the server and useLayoutEffect() in the browser