How can you skip an update after a prop update as you need to yield on each iteration?
If you have a stateful component you can render a special <Copy /> element instead of what you rendered previously to prevent the children from updating.
function equals(props, newProps) {
for (const name in {...props, ...newProps}) {
if (props[name] !== newProps[name]) {
return false;
}
}
return true;
}
function memo(Component) {
return function *Wrapped({props}) {
yield <Component {...props} />;
for (const newProps of this) {
if (equals(props, newProps)) {
yield <Copy />;
} else {
yield <Component {...newProps} />;
}
props = newProps;
}
};
}
You can read more about the special element tags here: https://crank.js.org/guides/special-tags-and-props
That鈥檚 beautiful
Wouldn't it be possible to implement this feature with yield null?
@lazeebee I鈥檓 pretty sure that yield nullwill make your component render nothing which is what most would expect to happen. Copy will keep the UI the same without actually calling render again
Most helpful comment
If you have a stateful component you can render a special
<Copy />element instead of what you rendered previously to prevent the children from updating.