Skip to content

Commit ea9b11d

Browse files
committed
Document for third-party renderers
1 parent 82eb67f commit ea9b11d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/react-reconciler/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ You can proxy this to `queueMicrotask` or its equivalent in your environment.
211211

212212
This is a property (not a function) that should be set to `true` if your renderer is the main one on the page. For example, if you're writing a renderer for the Terminal, it makes sense to set it to `true`, but if your renderer is used *on top of* React DOM or some other existing renderer, set it to `false`.
213213

214+
#### `getCurrentEventPriority`
215+
216+
To implement this method, you'll need some constants available on the _returned_ `Renderer` object:
217+
218+
```js
219+
const HostConfig = {
220+
// ...
221+
getCurrentEventPriority() {
222+
return MyRenderer.DefaultEventPriority;
223+
},
224+
// ...
225+
}
226+
227+
const MyRenderer = Reconciler(HostConfig);
228+
```
229+
230+
The constant you return depends on which event, if any, is being handled right now. (In the browser, you can check this using `window.event && window.event.type`).
231+
232+
* **Discrete events:** If the active event is _directly caused by the user_ (such as mouse and keyboard events) and _each event in a sequence is intentional_ (e.g. `click`), return `MyRenderer.DiscreteEventPriority`. This tells React that they should interrupt any background work and cannot be batched across time.
233+
234+
* **Continuous events:** If the active event is _directly caused by the user_ but _the user can't distinguish between individual events in a sequence_ (e.g. `mouseover`), return `MyRenderer.ContinuousEventPriority`. This tells React they should interrupt any background work but can be batched across time.
235+
236+
* **Other events / No active event:** In all other cases, return `MyRenderer.DefaultEventPriority`. This tells React that this event is considered background work, and interactive events will be prioritized over it.
237+
238+
You can consult the `getCurrentEventPriority()` implementation in `ReactDOMHostConfig.js` for a reference implementation.
239+
214240
### Mutation Methods
215241

216242
If you're using React in mutation mode (you probably do), you'll need to implement a few more methods.

0 commit comments

Comments
 (0)