0

I have this view which is in the Controller, and item is passed as a prop.

render () {
    if (this.view) {
        const { item } = this.props;
        return <ViewComponent 
            item = {item}
        />;
    }
}

I have this other function save() which creates and save the payload.

I need to pass this payload as well present it to the save function as a prop to my view so I can use it.

save () {
    const payload = constructPayloadFunction();
    createFunction({ payload });
}

How do I do that?

kelsny
  • 23,009
  • 3
  • 19
  • 48
komal
  • 43
  • 6

1 Answers1

0

You have to create a function in you Controller

public createFunction(payload){....}

and pass this as a prop to your ViewComponent

if (this.view) {
   const { item } = this.props;
   return <ViewComponent 
   item = {item}
   createFunction = {createFunction}
   />;
}

and finally, in your save function, just pass the result

const payload = constructPayloadFunction();
createFunction(payload);
Tirth Trivedi
  • 155
  • 1
  • 6
  • What do we send as a payload to ViewComponent? How do we access the createFunction in View Component? What parameter we will pass it there? – komal May 23 '22 at 14:31
  • It will be passed as prop and you have to access it the same way you would have accessed the item prop. The parameter that we pass to that function will be simply the payload object that gets created. – Tirth Trivedi May 23 '22 at 14:42