Gathering detailed insights and metrics for react-clientside-effect
Gathering detailed insights and metrics for react-clientside-effect
Gathering detailed insights and metrics for react-clientside-effect
Gathering detailed insights and metrics for 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
Create components whose nested prop changes map to a global side effect
npm install react-clientside-effect
93.3
Supply Chain
98.5
Quality
75.5
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
94 Commits
3 Forks
3 Watching
3 Branches
1 Contributors
Updated on 06 May 2022
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
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
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
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
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
58 existing vulnerabilities detected
Details
Score
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 More