我正在使用带有样式组件的钩子。单击"我要显示DropdownContentUI
"。如何将道具从状态传递给UI组件?
const DropdownContentUI = styled.div`
display: ${props=>props.isOpen ? 'inline-flex' : 'none'};
position: absolute;
background-color: #f9f9f9;
top: 100%;
left: 0;
z-index: 1;
flex-flow: column;
`;
const DropdownArrows = () => {
const [isOpen, setTrigger] = useState(false);
return (
<DropdownArrowsUI onClick={()=> setTrigger(!isOpen)} isOpen>
<DropdownArrowsWrapperUI>
<DropdownIconUI width="8" height="11" viewBox="0 0 8 11">
<path d="M1 4.04L4.04 1L7.08 4.04" stroke="#BACCD8" />
<path d="M7.08008 6.46L4.04008 9.5L1.00008 6.46" stroke="#BACCD8" />
</DropdownIconUI>
</DropdownArrowsWrapperUI>
<DropdownContentUI>
<DropdownArrowsWrapperUI>
<DropdownIconUI width="8" height="7" viewBox="0 0 8 7">
<path d="M1 4.04L4.04 1L7.08 4.04" stroke="#177FF2" />
<path d="M4 4V7" stroke="#177FF2" />
</DropdownIconUI>
</DropdownArrowsWrapperUI>
</DropdownContentUI>
</DropdownArrowsUI>
);
};
<DropdownContentUI isOpen={isOpen}/>
如果您只是输入 isOpen
,它将始终为 true
或者,
在这种情况下,您可以使用条件呈现。
{isOpen && <DropdownContentUI/>}