Best way to conditional render React components and keep it DRY(条件渲染 React 组件并保持 DRY 的最佳方法)
问题描述
我有一个应用程序在删除时显示确认模式.
这是完整的代码:
https://codesandbox.io/s/vkz5xm8r0
在 components/Modal.js 我有一些条件渲染.如果我想根据这些条件设置整个模式的样式怎么办?最好的方法是什么?
例如.如何设置整个模态的样式,使其外观改变如下:
https://imgur.com/a/pK5Zu
重新组织了一下代码.我相信这会使代码更简洁,更容易设计样式.并希望回答你的问题:)
I have an app showing confirmation modal on delete.
Here is the full code:
https://codesandbox.io/s/vkz5xm8r0
In components/Modal.js I have some conditional render. What if I want to style the whole modal based on those conditions? What is the best way to do so?
Eg. how to style the whole modal so it changes appearance like so:
https://imgur.com/a/pK5Zu
Reorganised the code a bit. I believe this makes the code cleaner and easier to style. And hopefully answers your question :)
这篇关于条件渲染 React 组件并保持 DRY 的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!