如何解决通过样式组件声明中的settimeout返回样式
export const MotionDiv = styled(motion.div)`
background: ${props => props.showSlides ? 'red' : 'blue'};
${({showSlides}) => (showSlides ? ShowSlides() : null)};
`
const ShowSlides = () => {
console.log('show slides function fires')
let styling = ``
setTimeout(() => {
styling = `background: yellow !important;`
},100);
console.log('its lit',styling)
return styling
}
我已经尝试了多次尝试,并且有点像js noob,但我的控制台正在触发日志,因此即时通讯知道prop已成功调用该函数,但未返回样式
任何帮助都非常感激..
非常感谢
詹姆斯
解决方法
const timeout = setTimeout(() => {
setShowSlidesStyling(true)
},3000);
// return () => clearTimout(timeout);
},[])
结果证明setTimeout不能返回,因此useEffect通过控制状态来控制道具,道具会触发功能,道具会触发样式==}}喊出simon adcock以获得答案
,也许只是删除函数,而只是在setTimeout中返回字符串?
export const MotionDiv = styled(motion.div)`
background: ${props => props.showSlides ? 'red' : 'blue'};
${({showSlides}) => (showSlides ? setTimeout(() => 'background: yellow !important;',100) : null)};
`
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。