Skip to main content
scopeBind<T>(event: Event<T>): (payload: T) => void

A method to bind event or effect to a scope to be called lated. effector supports imperative event calling inside watchers but sometimes you should bind events to the scope explicitly, e.g. when calling events within a setTimeout/setInterval callbacks.

Arguments

  1. event Event to be bound to the scope

Example#

We are going to call changeLocation inside history.listen callback so there is no way for effector to associate event with corresponding scope and we should explicitly bind event to scope using scopeBind

const installHistory = app.createEvent<any>()
const changeLocation = app.createEvent<string>()
installHistory.watch(history => {
const locationUpdate = scopeBind(changeLocation)
history.listen(location => {
locationUpdate(location.pathname)
})
})

See full example

Last updated on