U
U
uRoot2020-05-01 16:04:24
React
uRoot, 2020-05-01 16:04:24

How to call a function from a child component?

I have an App parent:

render() {
    return (
      <div>
        <Filtered items={this.state.items} />
      </div>
    )
  }

And I want to execute a function (without an event) in the Filtered component by passing this.state.items there. How can I do it? And now I have in Filtered my JS code is executed from render (), but I would like that in render () I had only the result of the function.

UPD as far as I understand, if there is a need for such an action, then this indicates that something is wrong in the application architecture. And that there is nothing wrong with passing props to the component, which is processed in return(). I'm not really sure about the last one though.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-05-01
@hzzzzl

my JS code is executed from render(), and I would like that in render() I have only the result of the function execution

what exactly needs to be done?
render() {
  return (
   <div> 
    { this.props.items.map(item => <div>{ item.someText }</div>) }
   </div>
   )
}

if you somehow process the items and render them, then this is quite the norm, otherwise nothing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question