文章
问答
冒泡
React中函数组件接收子组件参数
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useState } from 'react';
const Fater = () => {
    const [title, setTitle] = useState<string>('第一个标题')

    const changeTitle = (title: string) => {
        setTitle(title)
    }

    return(
        <>
            <Child title={ title } changeTitle={ changeTitle }/>
        </>
    )
}

const Child = (props: any) => {
    const { changeTitle, title } = props;
    return(
        <>
            <h1>{ title }</h1>
            <button onClick={ () => { changeTitle('第二个标题') } }>
                更改标题
            </button>
        </>
    )
}
reacr

关于作者

zhyim
学海无涯,回头是岸
获得点赞
文章被阅读