react typescript 子組件給父組件傳值


//父組件

import * as React from 'react'
import { Input } from 'antd'
const Search = Input.Search
import "./index.less"
import Child from "./compon/list"
export default class ProjectList extends React.Component<IProps>{
constructor(props: IProps) {
super(props)

}

handle = (val) => {  //val就是子組件傳的值1
console.log(val)
// this.setState({
// mess:val
// })
}render(){
   
return (
<div>
 
  <Child  GETState= {this.handle.bind(this)} /> // 這種tslint git提交報bind錯誤
  <Child  GETState= {(val)=>this.handle(val)} />
  </div>
)
}

}
//子組件
import * as React from 'react'
import { Row, Col } from 'antd';
import "./list.less"

interface IProps {
msg?: any
MakeMoney?:any
GETState?: any //主要這段代碼
}
interface IState {
lg?: any

}
export  default class List extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props)

}
state = {
lg: 6,
a:68
}
toggle = () => {
console.log('f')
this.setState({
lg: 12
})
}


render(){
console.log(this.props.msg)
const { lg } = this.state;
return (
<div>
<button onClick={() => this.props.GETState(this.state.a)}>子組件</button>
  )
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM