Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

React hook中 对于useState为什么会采用替换的策略?

在看到公司架构师写的一篇文章里提到了:
class组件对于state的处理策略是 合并,而hooks中的策略就变成了 替换
因为文章中没有给出很好的解释,我在论坛上也没有看到太多的讨论,所以提问。
为什么hooks的state的策略是替换?
??:

    class APP extend Component {
        constructor() {
            this.steState({})
        }
    }
    
    const App = () => {
        const [state, setState] = useState({})
        useEffect(() => {
            setState({})
        }, [])
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

关注一下,我觉得对使用者来说是一样的操作,保证纯净


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...