New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"setState" on componentDidMount #4
Comments
$componentDidMount = $props
.skip(1)
.take(1);
// Or just
$propsAfterMount = $props.skip(1); This is a good topic for the docs, thanks! |
@acdlite But this There are situations (for example to detect size of component) where real componentDidMount is needed. |
Thx @acdlite. I tried your suggestion with no success. TestContainer doesn't receive any props from his parent so componentWillReceiveProps is never called. |
@efflam So your example would look like: const TestContainer = createRxComponent(props$ => {
const containerRef$ = funcSubject()
const resize$ = Observable
.fromEvent(window, 'resize');
const size$ = Observable.combineLatest(containerRef$, resize$,
containerRef => React.findDOMNode(component))
.map( el => ({ width: el.innerWidth, height: el.innerHeight }) )
.startWith({ width: 0, height: 0 })
return Observable.combineLatest(props$, size$, $containerRef, (props, { width, height }, containerRef) => ({
...props,
containerRef
width,
height
}))
}, Test)
function Test(props){
const { width, height, containerRef } = props
return (
<div ref={containerRef}>
<p>width: {width}</p>
<p>height: {height}</p>
</div>
)
} EDIT: fixed (I believe) |
^ Btw I don't think that will work until #5 is fixed. I'll look at it today and write a test case to confirm. |
so whats the best way to do it |
Hi
I'm trying to create a smart component to retrieve window size and pass it as props to the dumb component. It works fine when I resize the window.
I was wondering how i could update width and height on componentDidMount with this approach.
The text was updated successfully, but these errors were encountered: