javascript - 有没有办法在 checkBox 上的 onchange 事件上重新渲染组件
问题描述
在这里,我试图通过 onchange 事件将文本的样式更改为行槽,但组件没有重新渲染,样式也没有改变。
import React from 'react';
import {useDispatch} from 'react-redux'
import {DelAction,CompleteAction} from '../Action'
function Todo(props) {
//assigning dipsatch
const dispatch=useDispatch();
//Delete the Todo form the store
const getStyle=()=>{
return{
textDecoration:props.todo.completed?'line-through':'none',
backgroundColor:'rgb(20%,50%,60%)',
borderBottom:'1px #000 dotted',
}
}
return (
<div style={getStyle()} >
<p style={{fontSize:'20px'}}>
<input type="checkbox" onChange={()=> dispatch(CompleteAction(props.todo.id))}/>
<button style={{float:'right'}} onClick={ () => dispatch(DelAction(props.index) )} >Delete</button>
</p>
</div>
);
}
export default Todo;
解决方案
推荐阅读
- angular - 使用翻译管道(ngx-translate),字符串被读取,但它仍然给出“无法读取属性”错误(Angular 6)
- javascript - 使用 BigInt 将 Int64 从 .net 服务传递到 Javascript
- c# - 当字符串中只有两个时获取特定字符的第二个索引
- xcode - TouchId 和 FaceId 授权条件
- ios - 我正在尝试以编程方式创建 UI,但滚动视图和文本视图无法正常工作
- java - 按升序对连接和分组的记录进行排序
- angular - Angular Universal 是否提供 JIT 或 AOT 编译?
- java - 如何在不实际重新加载 JSP 页面的情况下单击下一个/上一个按钮逐个打印数据(arraylist 的对象)?
- google-sheets - 如何在 Google Data Studio 中同时使用 SUM () 和 CASE () 计算总金额?
- java - 使用 Lucene Query 测试文档是否匹配