2023. 7. 15.

Passing custom event function from parent component to child in react

 


Passing  function  from parent to child component 
for click-event customizing 

1) define function in app level

    function. custom_event (key, event) {

      // this is custom function 

      console.log ("call custom function ") ;

    }

2) passing custom function to child by property

     when click item ,  item calls internalClick

       custom_event function is called by name "customFunction" in internalClick function 

        


// in app.js     

  function. custom_event (key, event) {

      // this is custom function 

      console.log ("call custom function ") ;

    }

 <BoardList  customFunction= { this.props.custom_event }  />    


//  in BoardList.js

      // some loop ... 

     <BoardRow keyField={ this.props.keyField}   customFunction = { this.props.customFunction} /> 


//  in BoardRow.js 

     <BoardItem keyField={ this.props.keyField} customFunction = { this.props.customFunction} /> 

// in BoardItem.js 

     internalClick = (e) => {

       console.log ( "click item ") ;

       this.props.customFunction(this.props.keyField , e) ;

     }

    render() {

          return (<button  onClick = { this.internalClick } > click </button>)

    }

    

      

    



Python new string format (update) f-string

 Update .. 

Late news 


My previous post:  2016 

https://blog.boxstory.com/2016/08/python-new-string-format.html


New Addition  :  f-string   ( support  from 3.6 )

variable = 'hello'
print(f' my variable is {variable}') # using f' xxxx {variable_name}'


 # output 
my variable is hello 

# Yes , It's very simple and powerful.