如何调整大小,然后用react redux渲染到画布上
How can I resize, then render to a canvas with react-redux
我正在编写一个react redux应用程序,但不知道如何在调整画布大小后对其进行渲染。
基本上,我有两个滑块,当更改时,它们会更新画布的宽度和高度。在我的reducer中,我可以在状态更新期间渲染到画布。但是,画布一旦接收到新的维度,就会被清除。
因此,我试图做的是更新状态,然后一旦React渲染了新调整大小的画布,我就需要对其进行渲染(最好是在保持画布尺寸的同一个reducer中)。
目前,我正试图用redux thunk这样做:
导出const setWidthAndRender=(宽度)=>(调度)=>{dispatch(setWidth(width));setTimeout(dispatch(renderToCanvas),10);};
不过,这不起作用。一旦我确定它已经由React渲染,我想以某种方式将renderToCanvas发送出去。
有什么想法吗?
您必须在画布状态中添加一个新属性,例如"newWidth",如果您必须重新渲染画布,则该属性为true,如果您不需要,则为false。
您的函数setWidth应该将newWidth更改为true,以便组件在下一次调用"componentDidUpdate"时知道您的宽度已经更改。
componentDidUpdate()应该看起来像这个
componentDidUpdate(){
let {newWidth} = this.props.canvasProps
let {renderToCanvas} = this.props.actions;
if(newWidth === true){
renderToCanvas(); // Set newWidth to false inside renderToCanvas()
}
}
这种方式应该有效:p
相关文章:
- React Redux错误页面管理
- React redux初始化功能,无论状态变化如何
- 为什么react/redux前端项目在package.json中包含生产依赖项
- React+Redux性能优化与组件ShouldUpdate
- React Redux无法让减速器拾取动作
- 使用Redux和React添加焦点更改类
- 使用react router/react router redux将特定的redux操作绑定到一个路由
- 类叶组件中的connect()是react+redux中反模式的标志吗
- React/redux应用程序在Safari上呈现空白屏幕
- react路由器(-redux)未匹配路由
- 在React Native+Redux中使用Navigator
- React-Redux React-router Store 在 props 中不可用
- redux/react 应用程序中的状态有一个带有化简器名称的属性
- redux-react simple hello world
- 连接在 Redux-react 中无法使用 Stateless 组件
- Redux React从API创建初始状态
- TypeScript Redux React:如何遍历组件子组件
- 为什么在redux-react Action中使用函数块promise ?
- redux-react在react子组件中操作props的方法是什么?
- Rails 5 Redux React Server 端渲染给出客户端 JavaScript 警告“用新的 ..” 替换