反应本土国家?

问题描述 投票:0回答:1

我正在尝试找到在React-Native中具有全局状态的方法。多个组件之间的共享状态,可以像正常状态一样自动重新渲染。但是对于所有组件。

我不想使用redux。

react-native
1个回答
0
投票

一个简单的解决方案是创建一个全局文件。

Global.js

export let GlobalValue = "";

export function setGlobalValue(data) {
  GlobalValue = data;
}

export function getGlobalValue() {
  return GlobalValue;
}

用法

import * as Global from 'global file path'

componentDidMount() {
  let globalVal = Global.getGlobalValue()
  console.log(globalVal)
}
© www.soinside.com 2019 - 2024. All rights reserved.