Call parent funtion from child

so i have a slider and a method to stop the slider and restart the slider, but i need to stop the slider based on the state of the children, so if the user press the child component the state change and i need to stop the slider but that function is in the slider component how can i call that function from the child this is my child component.

class SliderPromotions extends React.Component
{
    constructor()
    {
        super();
        this.state =
        {
            Promotion: false
        }
    }

    ShowPromotion = () =>
    {
        this.setState({ Promotion: !this.state.Promotion });
    }

    render()
    {
        return (
        <Slider StopSlider={this.state.Promotion}>
        {
            Data.map(function(DataValue)
            {
                return (
                    <Child onPress={() => this.ShowPromotion()}/>
                );
            }, this)
        }
        </Slider>
        );
    }

}

This is the slider component, when the state of the child is true will stop the slider and when is false will restart the slider

class Slider extends React.Component
{
     StopSlider = () =>
     {
        //this stop the slider
        //.......
        //I try this when I pass the prop but doesn't work
        if(!this.props.StopSlider)
        {
             
        }
     }

     RestartSlider = () =>
     {
         //this restart the slider
     }
     render()
     {
           return (
            <ScrollView>
                {
                    this.props.children
                }
            </ScrollView>
           );
     }

}

so i try to pass a prop from the SliderPromotion in the Slider component like this "StopSlider={this.state.Promotion}" but don’t work properly

I am thinking the way you should do this is pass the function to the children and then the children call that function but I don’t know how to do it if I have this.props.chlidren

363 thoughts on “Call parent funtion from child”

  1. [url=https://propranolol.site/]propranolol for sale uk[/url] [url=https://buspar.site/]buspar costs[/url] [url=https://vardenafil.men/]generic levitra buy[/url] [url=https://lisinopril.beauty/]lisinopril 60 mg[/url] [url=https://tetracycline.fun/]order tetracycline online without prescription[/url] [url=https://prednisolone.boutique/]purchase prednisolone[/url]

    Reply
  2. i need a loan shark, i need a loan desperately today. i need a direct payday loan lender need loan, i need a mortgage loan with bad credit, cash for payday loans, cash advance, cash advances, cash advance loans for pensioners. Business describes banking, internationally active. loan direct lender i need a loan advance fast personal loan.

    Reply

Leave a Comment