# react-reconciler
This is an experimental package for creating custom React renderers.
**Its API is not as stable as that of React, React Native, or React DOM, and does not follow the common versioning scheme.**
**Use it at your own risk.**
## Usage
```js
const Reconciler = require('react-reconciler');
const HostConfig = {
// You'll need to implement some methods here.
// See below for more information and examples.
};
const MyRenderer = Reconciler(HostConfig);
const RendererPublicAPI = {
render(element, container, callback) {
// Call MyRenderer.updateContainer() to schedule changes on the roots.
// See ReactDOM, React Native, or React ART for practical examples.
}
};
module.exports = RendererPublicAPI;
```
## Practical Examples
A "host config" is an object that you need to provide, and that describes how to make something happen in the "host" environment (e.g. DOM, canvas, console, or whatever your rendering target is). It looks like this:
```js
const HostConfig = {
createInstance(type, props) {
// e.g. DOM renderer returns a DOM node
},
// ...
supportsMutation: true, // it works by mutating nodes
appendChild(parent, child) {
// e.g. DOM renderer would call .appendChild() here
},
// ...
};
```
**For an introduction to writing a very simple custom renderer, check out this article series:**
* **[Building a simple custom renderer to DOM](https://medium.com/@agent_hunt/hello-world-custom-react-renderer-9a95b7cd04bc)**
* **[Building a simple custom renderer to native](https://medium.com/@agent_hunt/introduction-to-react-native-renderers-aka-react-native-is-the-java-and-react-native-renderers-are-828a0022f433)**
The full list of supported methods [can be found here](https://github.com/facebook/react/blob/main/packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js). For their signatures, we recommend looking at specific examples below.
The React repository includes several renderers. Each of them has its own host config.
The examples in the React repository are declared a bit differently than a third-party renderer would be. In particular, the `HostConfig` object mentioned above is never explicitly declared, and instead is a *module* in our code. However, its exports correspond directly to properties on a `HostConfig` object you'd need to declare in your code:
* [React ART](https://github.com/facebook/react/blob/main/packages/react-art/src/ReactART.js) and its [host config](https://github.com/facebook/react/blob/main/packages/react-art/src/ReactARTHostConfig.js)
* [React DOM](https://github.com/facebook/react/blob/main/packages/react-dom/src/client/ReactDOM.js) and its [host config](https://github.com/facebook/react/blob/main/packages/react-dom/src/client/ReactDOMHostConfig.js)
* [React Native](https://github.com/facebook/react/blob/main/packages/react-native-renderer/src/ReactNativeRenderer.js) and its [host config](https://github.com/facebook/react/blob/main/packages/react-native-renderer/src/ReactNativeHostConfig.js)
If these links break please file an issue and we’ll fix them. They intentionally link to the latest versions since the API is still evolving. If you have more questions please file an issue and we’ll try to help!
## An (Incomplete!) Reference
At the moment, we can't commit to documenting every API detail because the host config still changes very often between the releases. The documentation below is **provided in the spirit of making our best effort rather than an API guarantee**. It focuses on the parts that don't change too often. This is a compromise that strikes a balance between the need for a fast-paced development of React itself, and the usefulness of this package to the custom renderer community. If you notice parts that are out of date or don't match how the latest stable update is behaving, please file an issue or send a pull request, although a response might take time.
#### Modes
The reconciler has two modes: mutation mode and persistent mode. You must specify one of them.
If your target platform is similar to the DOM and has methods similar to `appendChild`, `removeChild`, and so on, you'll want to use the **mutation mode**. This is the same mode used by React DOM, React ART, and the classic React Native renderer.
```js
const HostConfig = {
// ...
supportsMutation: true,
// ...
}
```
If your target platform has immutable trees, you'll want the **persistent mode** instead. In that mode, existing nodes are never mutated, and instead every change clones the parent tree and then replaces the whole parent tree at the root. This is the node used by the new React Native renderer, codenamed "Fabric".
```js
const HostConfig = {
// ...
supportsPersistence: true,
// ...
}
```
Depending on the mode, the reconciler will call different methods on your host config.
If you're not sure which one you want, you likely need the mutation mode.
#### Core Methods
#### `createInstance(type, props, rootContainer, hostContext, internalHandle)`
This method should return a newly created node. For example, the DOM renderer would call `document.createElement(type)` here and then set the properties from `props`.
You can use `rootContainer` to access the root container associated with that tree. For example, in the DOM renderer, this is useful to get the correct `document` reference that the root belongs to.
The `hostContext` parameter lets you keep track of some information about your current place in the tree. To learn more about it, see `getChildHostContext` below.
The `internalHandle` data structure is meant to be opaque. If you bend the rules and rely on its internal fields, be aware that it may change significantly between versions. You're taking on additional maintenance risk by reading from it, and giving up all guarantees if you write something to it.
This method happens **in the render phase**. It can (and usually should) mutate the node it has just created before returning it, but it must not modify any other nodes. It must not register any event handlers on the parent tree. This is because an instance being created doesn't guarantee it would be placed in the tree — it could be left unused and later collected by GC. If you need to do something when an instance is definitely in the tree, look at `commitMount` instead.
#### `createTextInstance(text, rootContainer, hostContext, internalHandle)`
Same as `createInstance`, but for text nodes. If your renderer doesn't support text nodes, you can throw here.
#### `appendInitialChild(parentInstance, child)`
This method should mutate the `parentInstance` and add the child to its list of children. For example, in the DOM this would translate to a `parentInstance.appendChild(child)` call.
This method happens **in the render phase**. It can mutate `parentInstance` and `child`, but it must not modify any other nodes. It's called while the tree is still being built up and not connected to the actual tree on the screen.
#### `finalizeInitialChildren(instance, type, props, rootContainer, hostContext)`
In this method, you can perform some final mutations on the `instance`. Unlike with `createInstance`, by the time `finalizeInitialChildren` is called, all the initial children have already been added to the `instance`, but the instance itself has not yet been connected to the tree on the screen.
This method happens **in the render phase**. It can mutate `instance`, but it must not modify any other nodes. It's called while the tree is still being built up and not connected to the actual tree on the screen.
There is a second purpose to this method. It lets you specify whether there is some work that needs to happen when the node is connected to the tree on the screen. If you return `true`, the instance will receive a `commitMount` call later. See its documentation below.
If you don't want to do anything here, you should return `false`.
#### `prepareUpdate(instance, type, oldProps, newProps, rootContaine
没有合适的资源?快使用搜索试试~ 我知道了~
react-18.0.0.zip
共2000个文件
js:1681个
json:90个
css:79个
需积分: 0 0 下载量 136 浏览量
2024-05-04
14:37:38
上传
评论
收藏 7.29MB ZIP 举报
温馨提示
react.js for windows 各个版本,免费下载 前端三大框架之一 react 各个版本,免费下载 如果下载不了,关注我,评论区联系我 React 是一个库。它允许你将组件放在一起,但不关注路由和数据获取。要使用 React 构建整个应用程序,建议使用像 Next.js 或 Remix 这样的全栈 React 框架。
资源推荐
资源详情
资源评论
收起资源包目录
react-18.0.0.zip (2000个子文件)
style.css 4KB
shared.css 3KB
SettingsShared.css 2KB
Profiler.css 2KB
codemirror-paraiso-dark.css 2KB
Element.css 2KB
OwnersStack.css 2KB
TabBar.css 2KB
index.css 2KB
InspectedElementView.css 2KB
InspectedElement.css 2KB
EventTooltip.css 1KB
Tree.css 1KB
InspectedElementHooksTree.css 1KB
hydration.css 1KB
Components.css 1KB
InspectedElementErrorsAndWarningsTree.css 1KB
DevTools.css 1KB
Timeline.css 1009B
SnapshotCommitList.css 995B
SidebarSelectedFiberInfo.css 991B
StyleEditor.css 986B
main.css 926B
SidebarCommitInfo.css 922B
Toggle.css 907B
KeyValue.css 893B
InspectedElementSharedStyles.css 891B
EditableValue.css 870B
SnapshotSelector.css 858B
LayoutViewer.css 826B
RecordToggle.css 816B
SettingsModal.css 810B
ModalDialog.css 809B
Button.css 697B
SearchInput.css 693B
UnsupportedBridgeProtocolDialog.css 689B
ChartNode.css 626B
HoveredFiberInfo.css 598B
ContextMenuItem.css 592B
TimelineNotSupported.css 591B
ProfilingImportExportButtons.css 522B
Tooltip.css 517B
SnapshotCommitListItem.css 483B
Badge.css 475B
styles.css 460B
Chrome.css 394B
Updaters.css 392B
HocBadges.css 387B
Tooltip.css 373B
WhatChanged.css 356B
root.css 350B
NewArrayValue.css 327B
UnsupportedVersionDialog.css 314B
styles.css 303B
AutoSizeInput.css 288B
NoCommitData.css 282B
SelectedTreeHighlight.css 269B
ListItem.css 260B
Page.css 243B
ContextMenu.css 226B
index.css 189B
List.css 189B
EditableName.css 187B
NewKeyValue.css 159B
CommitFlamegraph.css 151B
ExpandCollapseToggle.css 135B
WarnIfLegacyBackendDetected.css 127B
ReactLogo.css 120B
InspectedElementStyleXPlugin.css 104B
index.css 90B
index.css 87B
CanvasPage.css 84B
ButtonIcon.css 69B
LoadingAnimation.css 63B
Icon.css 63B
CommitRanked.css 60B
shared.css 58B
InspectedElementErrorBoundary.css 28B
RootSelector.css 23B
index.html 24KB
index.html 9KB
app.html 8KB
index.html 7KB
index.html 3KB
index.html 3KB
index.html 2KB
index.html 2KB
index.html 2KB
canary.html 2KB
16.7.html 2KB
16.6.html 2KB
next.html 2KB
renderer.html 2KB
index.html 2KB
16.5.html 2KB
index.html 2KB
index.html 2KB
16.4.html 1KB
16.1.html 1KB
16.0.html 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
段子手-168
- 粉丝: 3937
- 资源: 2745
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功