Lottie react web error: Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') Author: Chuwen Time: 2022-10-29 Classification: React comment ##Error message ``` Uncaught TypeError: Cannot read properties of undefined (reading 'forEach') at Lottie2.deRegisterEvents (index.js:226:22) at Lottie2.componentWillUnmount (index.js:148:12) at callComponentWillUnmountWithTimer (react-dom.development.js:20413:14) at HTMLUnknownElement.callCallback2 (react-dom.development.js:3945:14) at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:16) at invokeGuardedCallback (react-dom.development.js:4056:31) at safelyCallComponentWillUnmount (react-dom.development.js:20420:5) at commitUnmount (react-dom.development.js:20951:11) at commitNestedUnmounts (react-dom.development.js:21004:5) at unmountHostComponents (react-dom.development.js:21290:7) ``` ! []( https://cdn.nowtime.cc/2022/10/29/580616896.png ) ##Causes View the error message. It seems that the 'eventListeners' variable is not an array or does not exist ! []( https://cdn.nowtime.cc/2022/10/29/92600442.png ) ##Solution Add this attribute and give an empty array to ` eventListeners` ```react <Lottie options={{ animationData: animation }} width={220} eventListeners={[]}/> ``` ! []( https://cdn.nowtime.cc/2022/10/29/1407110091.png )
React/Vue.js, etc.+PHP Storm (WebStorm) for breakpoint debugging Author: Chuwen Time: 2022-02-11 Classification: React comment ##Step 1: Start the project There are many ways to start a project. You can use the terminal mode to start, or you can use the * * run/configure debugging configuration provided with the IDE** The first mode is terminal mode startup: ! [yarn run dev]( https://cdn.nowtime.cc/2022/02/11/4228051095.png ) The second way is to run/configure debugging configuration startup: ! []( https://cdn.nowtime.cc/2022/02/11/572089405.png ) ##Configure Run/Configure Debug Configuration ! []( https://cdn.nowtime.cc/2022/02/11/872322467.png ) ##Fill in the project access address in Step 1 ! []( https://cdn.nowtime.cc/2022/02/11/570218.png ) Break point, start: ! []( https://cdn.nowtime.cc/2022/02/11/2368660618.png ) Commissioning: ! []( https://cdn.nowtime.cc/2022/02/11/457176485.png )
React+MobX (mobx utils) realizes deep monitoring value changes Author: Chuwen Time: 2022-02-10 Classification: React comment Related links: - https://github.com/mobxjs/mobx/issues/214#issuecomment -430218360 - https://github.com/mobxjs/mobx-utils#deepobserve ##Install mobx utils Mobx utils GitHub project address: https://github.com/mobxjs/mobx-utils `Yarn add mobx utils' or 'npm install -- save mobx utils` ##Using mobx utils This code is just sample code > ⚠️ Note that according to your own business logic, for example, call 'disposer()' after the page switch to log off listening, otherwise * * re registration * * deep listening will cause memory leakage! SettingsStore.ts: ```ts import {action, makeObservable, observable} from "mobx"; export interface ISettingsStore{ show: boolean; } export default class SettingsStore implements ISettingsStore { @observable public show: boolean = false; constructor() { makeObservable(this) } } ``` SettingsPage.tsx: ```ts const settingsStore = new SettingsStore() const disposer = deepObserve(settingsStore, (change, path) => { console.log(change) }) //Please note that according to your own business logic, such as calling disposer() to log off listening after page switching, or repeated registration of deep listening will cause memory leakage! // disposer() ``` --- ##Personal project practice 1. Put * * Registered Listener * * and * * Destroyed Listener * * into a file to export 2. On the required page (Page A), after initialization is completed (such as successfully obtaining data from the API), execute * * Register Listener** 3. Listen on the route, leave the A page event, and execute * * destroy the listener**
Mbox+ReactECharts does not update data Author: Chuwen Time: 2022-01-12 Classification: React comment Tsx is as follows: ``` <ReactECharts option={this.props.shipmentsLookupsChartStore?.getOptions}/> ``` The store is as follows: >If you follow the following 'setOptionsData', there will be a problem. The data has been given, but the view will not be updated ```ts import {action, computed, makeObservable, observable} from "mobx"; export default class ChartStore implements IChart { @observable public options = ChartOption; constructor() { makeObservable(this) } @computed get getOptions(): any { return this.options } @action.bound setOptionsData(data: ChartOptionsData): void { //Set x-axis data if (this.options?. xAxis[0]?. data) { this.options.xAxis[0].data = data.xAxisData; } } } ``` ###Solution >The reason is that the reason for deep and shallow cloning is only for record, and it does not guarantee that what I said is correct First, install 'lodash', and change the 'setOptionsData' method to the following, which will run normally: ```ts @action.bound setOptionsData(data: ChartOptionsData): void { //Deep clone data const newOption = cloneDeep(this.options) //Set x-axis data if (this.options?. xAxis[0]?. data) { newOption.xAxis[0].data = data.xAxisData } this.options = newOption } ```
React+Vite+TypeScript reads environment variables and reports an error: Uncaught ReferenceError: process is not defined Author: Chuwen Time: 2022-01-05 Classification: React comment Uncaught ReferenceError: process is not defined: Relevant sources: https://github.com/vitejs/vite/issues/1973#issuecomment -787571499 Solution: In 'vite. config. json': ```json import {defineConfig, loadEnv} from 'vite' import react from '@vitejs/plugin-react' export default ({mode}: { mode: string }) => { return defineConfig({ define:{ 'process.env':{...process.env, ...loadEnv(mode, process.cwd())} } }); } ``` Then name your environment variable file with 'VITE_', and then use 'process. env VITE_XXX ` Just get it