【发布时间】:2020-06-05 17:33:16
【问题描述】:
我是 react-native 的新手,我正在尝试为我的 react-native 分配创建一个按钮,但我不断收到意外的标记,语法错误。这是下面的代码(他们说错误在第 6 - 11 行)
我正在使用https://snack.expo.io/ 来测试我的代码
以下是它对以下错误所说的确切内容:
''' /module:/App.js: 意外令牌 (8:18)
6 - const Todo = props => (
7 - 查看>
8 - 标题="删除" />
9 - {props.todo.text}
10 - /查看>
11-)
评估模块://App.js.js
加载模块://App.js '''
由于某种原因,堆栈溢出它没有显示(视图、按钮、文本、滚动视图),但它们在那里,但您可以根据需要添加它们以使代码正常工作。
我查看了代码,但似乎无法得到我所缺少的,我将在此添加整个代码,以便您可以看到我正在使用的所有代码。
感谢您的帮助!
import React from 'react';
import {View, Button, Text, ScrollView} from 'react-native'
let id = 0
const Todo = props => (
<View>
<Button><onPress={props.onDelete}> title="delete" />
<Text>{props.todo.text}</Text>
</View>
)
export default class App extends React.Component {
constructor(){
super()
this.state = {
todos: [],
}
}
}
addTodo() {
id++
const text = 'TODO number ${id}'
this.setState({
todos: [
...this.state.todos,
{id: id, text: text, checked: false},
],
})
}
removeTodo(id) {
this.setState({
todo: this.state.todo.filter(todo => todo.id !
)
})
}
toggleTodo(id) {
this.setState({
todos: this.site.todo.map(todo => {
if (todo.id !== id) return todo
return {
id: todo.id
text: todo.text
checked: !todo.checked
}
})
})
}
render() {
return(
<View>
<Text>Todo count: this.state.todo.length}
</Text>
<Text>Unchecked todo count: this.state.todos.filter(todo => !todo.checked).length} </Text>
<Button onPress={() => this.addToDo()} title ="Add TODO" />
<ScrollView>
{this.state.todo.map(todo => (
<Todo
onToggle={() => this.toggleTodo(todo.id)}
onDelete={() => this.removeTodo(todo.id)}
todo={todo}
/>
))}
</ScrollView>
</View>
)
}
}
【问题讨论】:
标签: react-native