函数组件、类组件

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'

const useState = React.useState
const useCallback = React.useCallback

const Son = (props)=>{
  console.log(props)
  const [state,setState] = useState({name:1,age:20})
  const onClick = ()=>{
    setState({...state,name:2})
  }
  return (
    
son
{props.name}
{props.children}
name:{state.name}
age:{state.age}
) } class Grandson extends React.Component { constructor(parameters) { super() this.state = parameters console.log('parameters',parameters) } render(){ return (
grandson
this.change()}>grandObj.name:{this.state.grandObj.name}
grandObj.age:{this.state.grandObj.age}
) } change(){ this.setState({ grandObj:{...grandObj,name:222} }) } } const grandObj= {name:111,age:10} ReactDOM.createRoot(document.getElementById('root')!).render(
father
, )

你可能感兴趣的:(javascript,前端,react.js)