当前位置:网站首页>Discussion on mobx
Discussion on mobx
2022-06-09 20:16:00 【Front end Aaron】
Background introduction
- be relative to redux To put it simply , It is also an extensible state management library
- MobX from Mendix, Coinbase, Facebook Open source and many individual sponsors
- React and MobX It's a powerful combination ,React Responsible for rendering the state of the application ,MobX Responsible for managing application status for React Use
Browser support
- MobX5 The version runs on any support ES6 proxy You can use any browser on , I won't support it IE11, Node.js6
- MobX4 Can run on any support ES5 On the browser
- MobX5 and MobX4 Of API It's the same
preparation
- Because the browser does not support decorator Syntax , So add configuration
Enable decorator syntax support
Mode one :
1. npm run eject
2. npm install @babel/plugin-proposal-decorators
3. package.json
"babel": {
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
]
]
}
Mode two :
1. npm install react-app-rewired @babel/plugin-proposal-decorators customize-cra
2. Create... In the project root directory config-overrides.js
const {
override, addDecoratorsLegacy } = require("customize-cra");
module.exports = override(addDecoratorsLegacy());
3. package.json
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
}
solve vscode Editor warning about decorator Syntax
"javascript.implicitProjectConfig.experimentalDecorators": true
Generating project
- download MobX
npm install mobx mobx-react - Create objects that store state
// stores/TodoStore.js
import {
observable } from 'mobx'
class TodoStore {
// observable Represents observable data
@observable test: '';
@observable todos = [];
// towards todos Add data Change observable data prefix @action .bound change this Point to
@action.bound todoAdd () {
}
}
const todo = new TodoStore();
export default todo;
- hold todo Objects are placed globally
// stay index.js Import... Into the entry file
import todo from './stores/TodoStore';
import {
Provider } from 'mobx-react';
ReactDOM.render(
<Provider todo={
todo}><App /></Provider>,
document.getElementById('root');
);
// Use decorators in components that need to use global state todo Injected into this component props Inside , You also need another decorator to listen for changes to update the view
import React, {
Component } from 'react';
import {
inject, observer } from 'mobx-react';
@inject('todo'); // Inject store example
@observer // monitor store Instance change
class AddTodo extends Component {
render() {
const {
test } = this.props.todo;
return (
<header className="header">
{
test}
</header>
)
}
}
export default AddTodo;
边栏推荐
- Win7 64 bit ultimate installation office2003 prompt: "error 1919, error occurred when configuring ODBC data source MS Access database ODEC error"
- 下载最新的全球疫情历史数据,下载到当前日前两天
- 2022年GDCPC广东省大学生程序设计竞赛题解
- 牛客网:关于第K个数的一些排序问题
- Leetcode 1984. Différence minimale entre les notes des élèves (Oui, résolu)
- Logback日志配置文件添加颜色区分
- 苹果宣布 2022 年 Apple 设计大奖得主
- asp.net DataTable和Table的一些笔记
- Unity-UI-Scrollbar组件
- Question bank and answers for the 2022 National latest fire facility operator (senior fire facility operator) examination
猜你喜欢

More than observation | Alibaba cloud observable Technology Summit officially launched

ConvNets Principles
How to query the database with eloquent in laravel (select)

HMI 联机下载失败的问题及解决方案

下载最新的全球疫情历史数据,下载到当前日前两天

Babbitt | metauniverse daily must read: Citibank reported that the metauniverse economy represents $13 trillion in income opportunities, and there are five identified early investment opportunities

Neo4j desktop database backup

After the job interview failed, the interviewer roast in the circle of friends (heart tired)

Xcode 14 带来全新提升,Xcode Cloud 正式推出!

2022年全国最新消防设施操作员(高级消防设施操作员)考试题库及答案
随机推荐
平安证券开户有什么风险吗?安全的吗?
将excel中的合并单元格拆分并填充数据
95 ans plus tard, le programmeur de Big Factory a été condamné à neuf mois de prison pour avoir supprimé la bibliothèque.
Unity upgrade project to URP
种一棵树最好的时间是十年前,其次便是现在(C语言选择和循环训练题目)
Jerry's chart confirms that the project has not opened config_ NO_ SDRAM_ Enable macro, SDRAM used in the project [chapter]
How to view Tekton's pipeline indicators
Leetcode 1984. Différence minimale entre les notes des élèves (Oui, résolu)
Jerry's IO_ Key how to use double keys? [chapter]
博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现
Export CSV file from neo4j diagram database
FPGA入门实验-基于状态机实现多按键控制变速流水灯和跳变灯
【RK2206】4. Mqtt example
Numbers that occur only once (XOR, hash table)
Common regular expressions
Set creation and traversal methods
ASPX DataTable 行列互换
面试字节测开岗失败后,被面试官在朋友圈吐槽了......(心累)
2022 gdcpc Guangdong undergraduate program design competition
How to query the database with eloquent in laravel (select)