提前致谢。我有一个如下的状态数组。
我需要向状态数组添加一个项目,我发现我们不需要进行状态突变。我如何使用 prevState 设置状态。
const [messages, setMessages] = React.useState(
[
{
_id: 12,
createdAt: new Date(),
text: 'All good',
user: {
_id: 1,
name: 'Sian Pol',
}
},
{
_id: 21,
createdAt: "2019-11-10 22:21",
text: 'Hello user',
user: {
_id: 2,
name: 'User New'
}
}]
)
Run Code Online (Sandbox Code Playgroud)
我如何调用 set State 来附加这个状态数组。
像这样的东西?
setMessages(previousState => ({...stat
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我获得上述行代码。
当我尝试设置 React 导航时,我还安装了 React 本机手势处理程序。
我已按照主活动类中的以下链接添加了所有必需的想法。
我遇到这些错误:
\MainActivity.java:9: error: package com.swmansion.gesturehandler.react does not exist
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
^
D:\ReactNative\taskproject\android\app\src\main\java\com\taskproject\MainActivity.java:28: error: cannot find symbol
return new RNGestureHandlerEnabledRootView(MainActivity.this);
^
symbol: class RNGestureHandlerEnabledRootView
2 errors
Run Code Online (Sandbox Code Playgroud)
这有什么解决办法吗?过去两天我一直在敲头。或者我必须在 gradle.xml 中设置一些东西吗?我已经链接了反应反应手势,但它仍然对我不起作用。
提前致谢
我在 React Native Android 中使用西瓜数据库,它返回未定义的集合。
const handleDB = async () => {
const myCollection = database.collections.get('data_items')
await database.action(async () => {
const newPost = await myCollection.create(post => {
post.ItemID = 9
post.ItemParentItem_ID = 8
})
})
}
Run Code Online (Sandbox Code Playgroud)
我从同一个功能组件中调用它
handleDB()
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗
我的数据库
import { Database } from "@nozbe/watermelondb";
import SQLiteAdapter from "@nozbe/watermelondb/adapters/sqlite";
import { dbModel } from "./"
import { mySchema} from "./schema"
const adapter = new SQLiteAdapter({
dbName: 'Northel',
schema: mySchema
});
export const database = new Database({
adapter, …Run Code Online (Sandbox Code Playgroud) 我正在使用 Ant Design for React Js UI。我使用树组件显示在列表中。我还有 2 个按钮来展开和折叠树列表。我使用defaultExpandAll属性来管理它。在展开和折叠按钮上单击我分别将布尔值设置为 true 和 false。按钮在单击按钮时不会展开。如果我最初将 True 设置为该标志状态,它就会起作用。有什么解决办法吗?
我有 2 个组件。(展开和折叠按钮位于父组件中)
**Parent Component**
setExpandOrCollapse(value) {
this.setState({ expandOrCollapse: value });
}
<HeaderRow>
<Button onClick={() => this.setExpandOrCollapse(true)}>Expand All</Button>
<Button onClick={() => this.setExpandOrCollapse(false)}>Collapse All</Button>
</HeaderRow>
<Card>
{ItemTree && (ItemTree.length > 0) ? (
<ItemTree
dataSource={ItemTree}
expandOrCollapse={expandOrCollapse}
/>
) : null }
</Card>
**Child Component**
<Tree
draggable={isDraggable}
defaultExpandAll={expandOrCollapse}
>
{loopitemNodes(dataSource)}
</Tree>
Run Code Online (Sandbox Code Playgroud)
dataSource是从Redux api调用中获取的。
有什么解决办法吗?
一个新的反应本机,我有2个js文件(组件)。该文件的1是模式jsx,我想从其他js文件中打开此模式。
模态JS文件
import React, {Component} from 'react';
import { Platform, Text,View, StyleSheet, TouchableOpacity} from 'react-native';
import Modal from 'react-native-modal';
import { Icon,
Picker,
Form,
Item,
Button,
Input} from 'native-base';
export default class MyPopup extends Component{
state = {
isModalVisible: this.props.isModalVisible
};
constructor(){
super();
}
render() {
return (
<View style={styles.container}>
<Modal isModalVisible={true}>
onRequestClose={() => this.closeModal()}>
<View style={styles.headerContent}>
<View style={styles.headerItems}>
<Icon name='md-grid' />
<Text style={styles.headerText}>Version Mail</Text>
</View>
</View>
<View style={styles.modalContainer}>
<View style={styles.titleRow}>
<View style={styles.titleText}>
<Text>Book:</Text>
<Text> MAIN Reader</Text>
</View>
<View style={styles.titleTableText}> …Run Code Online (Sandbox Code Playgroud) 他预先感谢,React本机无法在模拟器中单击或打开开发模式。
react-native ×5
reactjs ×3
android ×2
react-props ×2
html ×1
react-hooks ×1
setstate ×1
watermelondb ×1