📌  相关文章
📜  在另一个组件中反应 setstate - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:37.858000             🧑  作者: Mango

代码示例1
// myContainer.js
import React, { useState } from 'react'
import MyChild from 'some/path/myChild'

function MyContainer() {
  const [name, setName] = useState('foo')

  return (
    
  )
}

export default MyContainer

// myChild.js
import React, { useCallback } from 'react'

function MyChild({ name, onNameChange }) {

  const handleInputChange = useCallback(event => {
    onNameChange(event.target.value)
  }, [onNameChange])

  return (
    
The name is: {name}
) } export default MyChild