我正在延长Textarea
,我希望completed
访问StyledItemTextarea
,而不是Textarea
。我怎样才能做到这一点?
import Textarea from 'react-textarea-autosize';
const TextareaAutosizeSC = styled(Textarea)`
...
`;
const StyledItemTextarea = TextareaAutosizeSC.extend`
color: ${({ completed }) => completed ? '#ccc' : '#fff'};
`;
const MyTextarea = ({ completed }) => <StyledItemTextarea completed={completed} />;
答案 0 :(得分:2)
也许是这样的:
const TextareaAutosizeSC = ({ completed, ...rest }) => {
const TextArea = styled(Textarea)`
...
`;
return <TextArea {...rest} />
}
或
const TextareaAutosizeSC = styled(Textarea)`
...
`;
const TextAreaWithoutSomeProps = ({ completed, ...rest }) => <TextareaAutosizeSC {...rest} />
答案 1 :(得分:1)
我找到了解决方法:
import Textarea from 'react-textarea-autosize';
const StyledItemTextarea = styled(({ completed, ...rest }) => <Textarea {...rest} />)`
color: ${({ completed }) => completed ? '#ccc' : '#fff'};
`;
const MyTextarea = ({ completed }) => <StyledItemTextarea completed={completed} />;