Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛[BUG] actionsRender,写了一个点赞、点踩,点击更新className高亮,没生效 #253

Closed
spiderT opened this issue Jun 18, 2024 · 3 comments

Comments

@spiderT
Copy link

spiderT commented Jun 18, 2024

🐛 bug 描述

actionsRender,写了一个点赞、点踩,点击更新className高亮,没生效

📷 复现步骤

actionsRender,写了一个点赞、点踩,点击更新className高亮,没生效

🏞 期望结果

在 actionsRender 里面打印feedbacks 没更新,但是外层feedbacks字段更新了

💻 复现代码

const [feedbacks, setFeedbacks] = useState<{}>({});

const submitFeedback = (type, id) => {

setFeedbacks({ ...feedbacks, id: type })

}

<ThumbsUp
theme="outline"
className={btn-icon ${feedbacks[id] === 'THUMB_UP' ? 'active' : ''}}
onClick={() => submitFeedback('THUMB_UP', id)}
/>

@spiderT
Copy link
Author

spiderT commented Jun 18, 2024

动态点赞更新className高亮,没生效,但是历史记录进来,是生效的。

问题貌似是,actionsRender 不支持动态更新,源码里这段useMemo的依赖项actions,组件使用时,应该怎么处理actions,可以让它动态更新

const actionsDom = useMemo(() => {
if (chatItemRenderConfig?.actionsRender === false) return null;
if (error) return null;
const dom = (
<Actions
actions={actions}
className={${cx(styles.actions, ${prefixClass}-list-item-actions)}}
/>
);
return chatItemRenderConfig?.actionsRender?.(props, dom) || dom;
}, [actions]);

@songhanlin
Copy link
Contributor

我是重写了ActionIconGroup, 实现了效果, 大概如下
const [cacheFeedback, setCacheFeedback] = useState(feedback || 0); const items: ActionIconGroupProps["items"] = [ { icon: () => { return ( <ThumbsUp size="12" color={cacheFeedback == 1 ? "#ff6600" : "rgba(0, 0, 0, 0.45)"} /> ); }, key: "thumbs-up", label: "赞", }]

@spiderT
Copy link
Author

spiderT commented Jun 24, 2024

我是重写了ActionIconGroup, 实现了效果, 大概如下 const [cacheFeedback, setCacheFeedback] = useState(feedback || 0); const items: ActionIconGroupProps["items"] = [ { icon: () => { return ( <ThumbsUp size="12" color={cacheFeedback == 1 ? "#ff6600" : "rgba(0, 0, 0, 0.45)"} /> ); }, key: "thumbs-up", label: "赞", }]

感谢,用这个方法可以解决

@spiderT spiderT closed this as completed Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants