Comments (9)
mapPropsOnUpdate()
is just a shortcut for compose(shouldUpdate(...), mapProps(...))
. If you want more control over when to update, use that.
from recompose.
It's not compose
of shouldUpdate
and mapProps
component may update and not recalculate some internal values.
Your code for mapPropsOnUpdate
does not contain any shouldComponentUpdate
calls.
And there is no method like
mapPropsOnUpdate(props => myCompareFn, props => newProps)
from recompose.
Ah you're right, clearly I don't know my own library well enough :)
Let me think about this one for a bit.
from recompose.
I know the implementation is slightly different, but is there any reason why compose(shouldUpdate(...), mapProps(...))
wouldn't achieve the desired effect?
from recompose.
I need to redraw but not to call again some intensive calculate function.
And in redraw i need result of that function.
And if some props changed, i need to run calculate function again after some additional checks.
Animation - in my current task.
I have map with svg tiles over it.
Instead of full svg path points position recalculation i can use css transforms until some props changes.
For example i scale on zoom oversimplified map tiles until tiles for new zoom level arrived.
Tiles preparation for swg drawing is really intensive task.
Also I can't call recalculate until google map stop animation (otherwise it breaks animation)
So i check shallow equality
on some props inside componentWillReceiveProps
,
and if it false
I make additional checks - could i reuse previous calculation partially or need to make full recalc again.
But I need to react on other props changes.
It's something like reduce
operation - take some new data, take previous result and create something new if needed.
from recompose.
I have a mostly-finished withReducer()
helper that I'll push soon. I think it may address your issue.
from recompose.
Thank you!!!
recompose
is really fun library.
from recompose.
Closed by #10
from recompose.
In combination with doOnReceiveProps
as like as I need
withReducer will cause Warning: setState(...): Cannot update during an existing state transition (such as within render).
Because of call to some parent setState
inside child constructor.
Calls actions inside componentWillReceiveProps
are OK but gives additional render.
IMHO this withReducer is good for most situations except mine.
All I need is this.
const createReduce = (reducer, BaseComponent) => (
class Reduce extends React.Component {
static displayName = wrapDisplayName(BaseComponent, 'Reduce');
constructor(props, context) {
super(props, context);
this.memo_ = reducer(undefined, props);
}
componentWillReceiveProps(nextProps) {
this.memo_ = reducer(this.memo_, nextProps);
}
render() {
return <BaseComponent {...this.props} {...this.memo_} />;
}
}
);
from recompose.
Related Issues (20)
- renderNothing should export Nothing HOT 4
- Does TypeScript 3.4 enable typing of compose HOT 1
- Remove flow types in repo and support only in flow-typed repo HOT 1
- Key advantages in Docs HOT 2
- The best way to test a component that use getContext recompose HOT 1
- Get a lifecycle componentDidMount unmounted error HOT 1
- Rewriting mapPropsStream with Hooks or new Lifecycle Methods HOT 4
- compose hoc causes to lose typings
- Remove usage of `createFactory` HOT 4
- Why does `mapProps` remove `children`? HOT 2
- node-fetch vulnerability issue (denial of service) HOT 8
- Forked, Updated, and Published HOT 1
- fbjs dependency still present in lock file HOT 3
- Support React 17 HOT 2
- Suggest alternative to branch(), renderComponent(), renderNothing(), compose(), etc
- TypeError: Cannot read properties of undefined (reading 'apply')
- Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
- New patch required to mitigate high risk vulnerability
- Maintainers HOT 1
- This is GITHUB and not the European Parliament or NATO.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recompose.