bs-react-notification-system

0.0.6 • Public • Published

Reason bindings for react-notification-system

npm

Reason bindings for react-notification-system.

Status

🚧 This is a WIP, not everything is supported yet. 🚧

Feel free to create an issue or PR if you find anything missing.

Installation

yarn add bs-react-notification-system
yarn add react-notification-system@0.2.x

Then add bs-react-notification-system to bs-dev-dependencies in your bsconfig.json:

{
  ...
  "bs-dev-dependencies": ["bs-react-notification-system"]
}

Usage

type action =
  | AddNotification(string);
 
type state = {
    _notificationSystem: ref(option(ReasonReact.reactRef)),
};
 
let setNotificationSystemRef = (notificationRef, {ReasonReact.state}) => 
  state._notificationSystem := Js.Nullable.to_opt(notificationRef) ;
 
let component = ReasonReact.reducerComponent("Notifications");
 
let addNotification = (message, state) => {   
    switch state._notificationSystem^ {
    | None => ()
    | Some(r) => ReasonReact.refToJsObj(r)##addNotification({"message": message, "level": "success"});      
    }
};
 
let make = (_children) => {
    ...component,
    initialState: () => {_notificationSystem: ref(None) },
    reducer: (action, state) =>
        switch action {
            | AddNotification(message) =>  ReasonReact.SideEffects(((_) => addNotification(message, state)))
        },
    render: ({handle, reduce}) => (
    <div>             
        <ReactNotificationSystem ref=(handle(setNotificationSystemRef)) />
        <button onClick=(reduce( (_) => AddNotification("Hello"))) > (ReasonReact.stringToElement("Click")) </button> 
    </div>
  )
};

Bindings

  • NotificationSystem

Package Sidebar

Install

npm i bs-react-notification-system

Weekly Downloads

0

Version

0.0.6

License

MIT

Last publish

Collaborators

  • bernalrs