Trigger will be called when matched action dispatches
Configure store with useTrigger
import { SinkFactory } from'redux-sink';// its also possible to add reducers and middlewares through this apiconststore=SinkFactory.createStore({... useTrigger: true,...});
Create sink with trigger
WeatherSink.js
import { sink, state, effect } from'redux-sink';@sink('weather')exportclassWeatherSink { @state loading =false; @state weather = { temperature:0, humidity:0 }; @effectasyncfunctionloadWeather() {this.loading =true;this.weather = async fetch('http://api/weather'); }// when weather action dispatches, set loading back to false @trigger('weather/weather')functionweatherTrigger(weather) {this.loading =false; }}