Optimization request: avoid rendering twice
jmike opened this issue · 3 comments
Hey,
I am using RxJS.BehaviorSubject
which allows me to get the latest value at any given time. That said, my component looks a bit like this...
const MyComponent = ({ subject$ }) => {
const data = useObservable(() => subject$, subject$.getValue());
return (
<h1>{data.name}</h1>
);
};
Also, in code-sandbox: https://codesandbox.io/s/jlkrpny969
The fact of the matter is that the component renders twice, although the initial state value is the same as the value returned from the inputFactory.
Would it be possible to avoid an extra render when the initial state matches the returned value?
seems like we should distinctUntilChanged
to the return value of useObservable
Hi @jmike, I'm using react 16.8.4 and I don't see any additional render with your code, would you like to have a try?
@icexxxxxx I confirm that there is no additional render with the latest react. Not sure how I missed this.
I've updated the codesandbox accordingly...
https://codesandbox.io/s/jlkrpny969
I am closing this issue. Thanks for the great support and all the hard work you put into this module.