Được TopGit lập chỉ mục từ metadata GitHub: gaearon/react-side-effect có 1.2k sao, viết chủ yếu bằng JavaScript. Create components whose nested prop changes map to a global side effect
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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:
and let the effect handler merge style from different level of nesting with innermost winning:
import { Component, Children } from 'react';
import PropTypes from 'prop-types';
import withSideEffect from 'react-side-effect';
class BodyStyle extends Component {
render() {
return Children.only(this.props.children);
}
}
BodyStyle.propTypes = {
style: PropTypes.object.isRequired
};
function reducePropsToState(propsList) {
var style = {};
propsList.forEach(function (props) {
Object.assign(style, props.style);
});
return style;
}
function handleStateChangeOnClient(style) {
Object.assign(document.body.style, style);
}
export default withSideEffect(
reducePropsToState,
handleStateChangeOnClient
)(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.
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.
Usage
Here's how to implement React Document Title (both client and server side) using React Side Effect:
import React, { Children, Component } from 'react';
import PropTypes from 'prop-types';
import withSideEffect from 'react-side-effect';
class DocumentTitle extends Component {
render() {
if (this.props.children) {
return Children.only(this.props.children);
} else {
return null;
}
}
}
DocumentTitle.propTypes = {
title: PropTypes.string.isRequired
};
function reducePropsToState(propsList) {
var innermostProps = propsList[propsList.length - 1];
if (innermostProps) {
return innermostProps.title;
}
}
function handleStateChangeOnClient(title) {
document.title = title || '';
}
export default withSideEffect(
reducePropsToState,
handleStateChangeOnClient
)(DocumentTitle);
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/gaearon/react-side-effect là nguồn chính thức.
gaearon/react-side-effect có bao nhiêu sao?
gaearon/react-side-effect có 1.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/gaearon/react-side-effect. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
gaearon/react-side-effect có phải mã nguồn mở không?
Có — gaearon/react-side-effect phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/gaearon/react-side-effect.
gaearon/react-side-effect có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho gaearon/react-side-effect. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
gaearon/react-side-effect có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho gaearon/react-side-effect. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
gaearon/react-side-effect còn đang phát triển không?
Commit gần nhất trên gaearon/react-side-effect là 3.7 năm trước (theo timestamp GitHub). Repo có 74 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về react-side-effect?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về react-side-effect.