All Projects → tkh44 → preact-smitty

tkh44 / preact-smitty

Licence: MIT license
Preact bindings for smitty

Programming Languages

javascript
184084 projects - #8 most used programming language

preact-smitty

npm version Build Status codecov

Preact bindings for smitty

npm install -S preact-smitty

Basics

const Title = track(
  // action type to update state on
  'ui/RESIZE',
  // key to pass as prop
  'screen',
  // select the value of 'screen' when the action is emitted
  state => state.ui.screen,
  // shouldTrackerUpdate = () => true
  (state, props, type, payload) => payload !== state.ui.screen
)(
  ({ screen, children }) =>
    screen < MEDIUM_SCREEN ? <h3>{children[0]}</h3> : <h1>{children[0]}</h1>
)

let mapStateToProps = (state, { id }) => {
  return {
    room: state.rooms[id]
  }
}
const Room = connect(mapStateToProps)(
  class Room extends Component {
    render ({ room = {} }) {
      console.log(room) // logs { id: '1', ... }
      return <Title>room.title</Title>
    }
  }
)

render(
  <Provider store={store}>
    <Room id={'1'}
  </Provider>,
  document.body
)

Demos (v2)

Demos (v1)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].