react-redux - 反应中样式化组件的类型
问题描述
我在我的项目中使用样式组件。并有这个组件
const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: #000;
`;
而且我不知道我需要为这个组件添加什么类型标题:React$ComponentType< any
> 工作,但我认为放任何都是坏主意。
我搜索我的问题并找到这个
type StyleValue = {[key: string]: Object} | number | false | null;
type StyleProp = StyleValue | Array<StyleValue>;
但它适用于本机反应,我无法为我的项目更新它
解决方案
我不确定你在问什么,但我会举一个例子,希望它能帮助你理解。请提供更多信息。下面我有我的Title
组件
const Title = ({
text,
textColor,
}) => {
return (
<StyledTitle textColor={color}>
{text}
</StyledTitle>
);
};
Title.propTypes = {
text: PropTypes.string,
textColor: PropTypes.string,
};
export default Title;
使用Styled-components
我然后有我的StyledTitle.js
文件:
const StyledTitle = styled.h1`
color: `${props => props.textColor} || black`;
font-size: 1.5em;
text-align: center;
`;
export default StyledTitle;
希望这对您有所帮助。
推荐阅读
- javascript - 如何通过表单外的按钮提交表单?
- gcc - Hello world shellcode 被正确执行,但没有打印到标准输出
- python - 列表推导的语法差异
- php - 在某些条件下更改行不透明度
- python-3.x - 返回嵌套字典中的特定值
- sql-server - SQL 链接服务器到 MS Access
- android - 如何在另一个活动中重用下载的图像?
- excel - 数据验证列表公式中的分隔符问题
- php - 如何在没有 symfony 的情况下使用 nelmio/api-doc-bundle?
- javascript - 如何从 (this) click 事件中提取 api url 的类名