可以直接在样式化的组件上定义propTypes和defaultProps吗?否则,我必须为默认导出命名。我只是想保持原样。组件:
import React from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
/**
* This component renders a div with a specified color.
*/
export default ({ color, children }) => <Box color={color}>{children}</Box>;
const Box = styled.div`
display: flex;
justify-content: center;
align-items: center;
border-radius: 4px;
color: white;
font-weight: bold;
font-size: 1.2rem;
background-color: ${({ color }) => color};
margin: 6px;
`;
Box.propTypes = {
color: PropTypes.string,
}
Box.defaultProps = {
color: "grey",
}