wiluxy 最近的时间轴更新
wiluxy

wiluxy

V2EX 第 368932 号会员,加入于 2018-12-08 01:17:13 +08:00
今日活跃度排名 4517
有 mac surge 的车吗
拼车  •  wiluxy  •  24 天前  •  最后回复来自 wogong
1
tableplus 拼车
拼车  •  wiluxy  •  111 天前
[深圳][18k-22k/月] 招聘全栈开发工程师(React、Node.js)
  •  1   
    酷工作  •  wiluxy  •  237 天前  •  最后回复来自 NerdHND
    17
    一个关于 react 函数组件重新渲染的问题
  •  1   
    React  •  wiluxy  •  2021-04-21 10:32:14 AM  •  最后回复来自 SystemLight
    25
    出日版 switch,购于去年 10 月,无盒,带保护包, 2000
    二手交易  •  wiluxy  •  2020-11-06 18:40:16 PM  •  最后回复来自 wiluxy
    28
    wiluxy 最近回复了
    4 天前
    回复了 stephenxiaxy 创建的主题 职场话题 仲裁的话, 2n 概率大吗
    这 2n 的赔偿如果你觉得是你应得的,那就去仲裁,写字楼里多的是软弱的人。
    生命会自己找到出路,你能来发这种帖子,说明这个环境下你不适合吃这碗饭
    vscode 的 continue 插件+mistra 的 codestral-latest 模型,真穷鬼套餐
    105 天前
    回复了 ooo4 创建的主题 React 请教一个关于 useEffect 依赖的问题
    @chesha1 useMemo 、useEffect 漏依赖的问题,可以装个 eslint 插件(@eslint-react/eslint-plugin
    )辅助查看依赖有没有问题,遵循 hooks 规则写下去,等以后 react compiler 完善自动优化吧,现在没有性能问题就不用管太多了,只要功能正常、没有性能问题,re-render 不是什么大事情,老是想着最佳实践很累的。
    105 天前
    回复了 ooo4 创建的主题 React 请教一个关于 useEffect 依赖的问题
    @ooo4 如果不加这个 currentChatId 可以满足你的功能,非要用 useEffect 的话,可以考虑一下用 useReducer 组织状态

    ```typescript
    import React, {useEffect, useReducer, useState} from "react"


    type Conversation = {
    id:string
    title:string
    [key:string]:unknown
    }

    const initialState:Conversation[] = [
    {id:'1',title:"title-1"},
    {id:'2',title:"title-2"},
    {id:'3',title:"title-3"},
    ]

    function App() {
    const [currentChatId,setCurrentChatId] = useState("")
    const [currentChatTitle,setCurrentChatTitle] = useState("")

    const [conversation,setConversation] = useReducer<
    React.Reducer<
    Conversation[],
    (prev:Conversation[],curChatId:typeof currentChatId)=>Conversation[]
    >
    >((prev,action)=>{
    console.log(123)
    return action(prev,currentChatId)
    },initialState)

    useEffect(()=>{
    if(currentChatTitle){
    setConversation((prev,curChatId)=>{
    console.log({curChatId})
    return prev.map(i=>{
    return {
    ...i,
    title: i.id === curChatId ? currentChatTitle : i.title,
    }
    })
    })
    }
    },[currentChatTitle])

    return <div>
    <label htmlFor="currentChatId">currentChatId:</label>
    <input type="text" id="currentChatId" value={currentChatId} onChange={(e)=>setCurrentChatId(e.target.value)} />
    <label htmlFor="currentChatTitle">currentChatTitle:</label>
    <input type="text" id="currentChatTitle" value={currentChatTitle} onChange={(e)=>setCurrentChatTitle(e.target.value)} />
    <ul>
    {
    conversation.map(i=>{
    return <li key={i.id}>{i.title}</li>
    })
    }
    </ul>
    </div>
    }

    export default App;


    ```
    105 天前
    回复了 ooo4 创建的主题 React 请教一个关于 useEffect 依赖的问题
    典型的滥用 useEffect 的例子,@MossFox 的方案是对的,至于 @chesha1 说的不推荐 useMemo ,这里 useMemo 的作用类似于派生状态,心智负担比用 useEffect 小
    那必须是这个
    https://overreacted.io/

    特别是这篇 useEffect 相关的
    https://overreacted.io/a-complete-guide-to-useeffect/
    116 天前
    回复了 nikelei 创建的主题 职场话题 28 岁大龄 javaer,失业中迷茫中
    @kandaakihito 样本不够,拿几个例子就总结出规律我觉得不太准确,我身边也有三本毕业一年,前端 12k 的案例
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1200 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:01 · PVG 02:01 · LAX 11:01 · JFK 14:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.