a react-announce declarative that exposes component size as a stream
npm install react-announce-sizea react-announce declarative that exposes component size as a stream.
npm i react-announce-size --save
`Usage
Say I need to set the width of something that has position: fixed equal to that of its parent container. I can do this using this module + the ever-useful @connect declarative.
`javascript
import {createSizeStream} from 'react-announce-size'
import {hydrate} from 'react-announce-hydrate'
import {connect} from 'react-announce-connect'
import {Component} from 'react'/*
The decorator will automatically dispatch the size of
Container component whenever the screen size changes or the component itself is re-rendered.
*/
const toolbar = createSizeStream()
@hydrate([toolbar.sync()])
class Container extends Component {
render () {
return (
Hello World!
)
}
}@connect({
size: toolbar.getStream()
})
class StickyTop extends Component {
render () {
const {left, right} = this.state
return (
STICKY PEOPLE
)
}
}``