我试图按onClick时删除div。div存在于我的父组件中
render() {
const listPlayers = players.map(player => (
<Counter
key={player.id}
player={player}
name={player.name}
sortableGroupDecorator={this.sortableGroupDecorator}
decrementCountTotal={this.decrementCountTotal}
incrementCountTotal={this.incrementCountTotal}
removePlayer={this.removePlayer}
handleClick={player}
/>
));
return (
<ContainLeft style={{ alignItems: 'center' }}>
<ProjectTitle>Score Keeper</ProjectTitle>
<Copy>
A sortable list of players that with adjustable scores. Warning, don't go negative!
</Copy>
<div>
<Stats totalScore={this.state.totalScore} players={players} />
{listPlayers}
</div>
</ContainLeft>
);
}
Run Code Online (Sandbox Code Playgroud)
它将道具传递到子组件,在该子组件上删除div的按钮在这里
return (
<div
style={{ display: this.state.displayInfo }}
className="group-list"
ref={sortableGroupDecorator}
id="cell"
>
<CountCell style={{ background: this.state.color }}>
<Row style={{ alignItems: 'center', marginLeft: '-42px' }}>
<Col>
<DeleteButton …Run Code Online (Sandbox Code Playgroud) 我试图用 props 控制左右属性,但不断出现错误
“语法错误:这是保留字”
我尝试了几种不同的方法(并查看了 StackO 上的各种示例)来解决我的答案并不断出现错误。我已经缩短了我的代码以了解这里的主要内容。
我的 App.js 中有这个,它可以与 Pulse.js 一起使用,直到我尝试传递 props
class App extends Component {
render() {
return (
<div className="App">
<Nav />
<Content />
<Pulse top="-124" left="300" />
</div>
);
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
这是 Pulse.js 的代码
class Pulse extends React.Component {
render() {
return (
<Star style={{top: {this.props.top} + 'em'}}></Star>
);
}
}
export default Pulse;
Run Code Online (Sandbox Code Playgroud)
当我输入“this.props.top”作为我的样式时,我收到错误。我尝试了各种方法来解决这个问题,但仍然出现错误。感谢您的帮助!
我试图将其添加到我的现有数组中,称为播放器(这是导入到我的父级中的外部文件“ players.js”)。
我可以写:
players.push({
name: 'Maul',
id: 26
});
Run Code Online (Sandbox Code Playgroud)
它用作ID用作键,并且名称在数组中更新。
但是如果我写
handleAddPlayer = () => {
console.log('i am working');
players.push({
name: 'Maul',
id: 26
});
};
Run Code Online (Sandbox Code Playgroud)
在我的按钮上
<div>
<h4>Add A Player</h4>
<input />
<button onClick={this.handleAddPlayer}>Press to Add Player</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我的状态如下:
this.state = {
id: players.id,
totalScore: 0,
countInfo: [],
evilName: '',
color: '#6E68C5',
scoreColor: '#74D8FF',
fontAwe: 'score-icon',
incrementcolor: '',
scoreNameColor: 'white',
glow: '',
buttonStyle: 'count-button-start',
players,
};
Run Code Online (Sandbox Code Playgroud)
这是行不通的。
从这里我有两个问题:
为什么当我单击按钮时它不会更新,但以前不能作为功能运行?
我想在输入中输入一个名称,并生成一个唯一键,该键添加到我的数组players.js中
我已经尝试过串联,但没有成功。