我想知道我是否必须做这样的事情来在我的react-native应用程序中使用AsyncStorage保存我的应用程序的整个商店,并在应用程序启动时检查它是否存在.
var store;
_loadInitialState = async () => {
try {
var value = await AsyncStorage.getItem(STORAGE_KEY);
if (value !== null){
store = value;
console.log('Recovered selection from disk: ' + value);
} else {
store = configureStore({});
console.log('Initialized with no selection on disk.');
}
} catch (error) {
console.log('AsyncStorage error: ' + error.message);
}
};
export default class App extends Component {
componentWillMount(){
this._loadInitialState().done()
}
render(){
return(
<Provider store={store}>
<AppContainer/>
</Provider>
)
}
}
Run Code Online (Sandbox Code Playgroud)
这不行,但我希望你明白这个想法.
我想要一个类似于 CSS 的东西,你可以为 div 提供“颜色”样式,并且其中的任何文本都会有它。
我在一个视图组件中有多个文本组件,我希望它们都具有相同的文本颜色。
如果我将“颜色”样式传递给视图,它会发出警告。
当他们的父母可以拥有所有孩子的风格时,我想避免将相同的风格传递给所有这些孩子。
我想从这里开始:
<View>
<Text style={styles.Warning}>
</Text>
<Text style={styles.Warning}>
</Text>
<Text style={styles.Warning}>
</Text>
<Text style={styles.Warning}>
</Text>
<Text style={styles.Warning}>
</Text>
</View>
Run Code Online (Sandbox Code Playgroud)
对此:
<View style={styles.Warning}>
<Text>
</Text>
<Text>
</Text>
<Text>
</Text>
<Text>
</Text>
<Text>
</Text>
</View>
Run Code Online (Sandbox Code Playgroud)
样式为:
const styles = StyleSheet.create({
Warning:{
color:'#a94442'
}
});
Run Code Online (Sandbox Code Playgroud)
(如果我不用安装任何东西就更好了)谢谢。
有没有办法在发送另一个之前判断屏幕上是否已经有Alert.alert()?
我有这个功能:
CheckInternet(){
if(this.props.json.undefined){
Alert.alert("Check your internet connection");
}
}
ComponentDidUpdate(){
this.CheckInternet();
}
Run Code Online (Sandbox Code Playgroud)
问题是我在该函数内部还有其他事情,我只是写了相关的代码,所以我不能把这个CheckInternet函数带到外面ComponentDidUpdate.
问题是组件在获取后会更新两次json,因此会发送两次警报.我想通过一个条件来防止同时发出两个警报,这个条件会让我知道屏幕上是否有警报.我似乎没有在Alert文档中找到类似的东西.有任何想法吗?
下面这个函数的最初想法是它应该只在ID匹配时返回卡(一个对象),但是它没有返回任何东西(它返回undefined):
showDetails(cards, id){
cards.map(function(card, index){
if(card.id==id){
console.log(card);
return card;
}
})
}
Run Code Online (Sandbox Code Playgroud)
然后我意识到我的返回范围错误,我需要返回循环返回的内容,所以我想出了这个:
showDetails(cards, id){
return (cards.map(function(card, index){
if(card.id==id){
return card;
}
}))
}
Run Code Online (Sandbox Code Playgroud)
上面代码的结果是:[undefined,Object]
我只是希望这个函数showDetails返回对象,而不是数组.
谢谢!
我想在几秒钟后自动关闭警报,而无需用户自己做。
如果可能的话,我想使用Alert(而不是AlertIOS)来做到这一点,但是如果只有AlertIOS有,那么我想我别无选择。
非常感谢你!
我正在尝试使用react-native-push-notifications基于React Native 附带的PushNotificationsIOS 的react-native 应用程序显示通知。问题是什么都没有发生,没有错误,没有通知,什么也没有。
我不确定是否在编写通知时出错,或者它在模拟器上不起作用。
谢谢!
react-native ×6
javascript ×3
alert ×1
alerts ×1
asyncstorage ×1
css ×1
dictionary ×1
function ×1
lifecycle ×1
object ×1
react-redux ×1
redux ×1
simulator ×1
store ×1
styles ×1
text ×1
view ×1