-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: set two state but re-render once #992
Conversation
yuanyan
commented
Mar 21, 2019
我跑了一下这个demo, click后 reRender为2,符合预期? rax: 1.0.0 rax-cli: 1.2 |
还没发版本 |
const { current } = create; | ||
if (current) { | ||
// Set this to true to prevent re-entrancy | ||
const previousIsRendering = Host.isUpdating; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块逻辑要下掉么? 因为目前的render或者forceUpdate更新是同步的,所以可能会和官方有些不一致的表现
比如把目前存在的case做个改造
it(
'in sync mode, useEffect is deferred and updates finish synchronously ' +
'(in a single batch with different state)',
() => {
const container = createNodeElement('div');
let logs = [];
function Counter(props) {
useEffect(
() => {
// Update multiple times. These should all be batched together in
// a single render.
render(<Counter count={2} />, container);
render(<Counter count={3} />, container);
render(<Counter count={4} />, container);
render(<Counter count={5} />, container);
render(<Counter count={6} />, container);
render(<Counter count={7} />, container);
},
[],
);
logs.push('Count: ' + props.count);
return <span>{'Count: ' + props.count}</span>;
}
render(<Counter count={0} />, container);
// Even in sync mode, effects are deferred until after paint
expect(logs).toEqual(['Count: 0']);
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 0');
// Now fire the effects
logs = [];
jest.runAllTimers();
// There were multiple updates, but there should only be a
// single render
expect(logs).toEqual(['Count: 7']);
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 7');
},
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed