1

I have this component:

const WizardView = () => {
  return (
    <Wizard finishButtonClick={() => {}} />
  );
};

The finishButtonClick function returns some value that I want to use and expects () => void Is there a way to use the value that finishButtonClick returns in another function?

For example something like this:

anotherFunction(finishButtonClickReturnValue);
2
  • @CaptainMhmdrz_A This comment is not useful, better try to explain what you think OP is doing wrong Commented Apr 2, 2020 at 16:31
  • returns some value that I want to use and expects () => void , this seems a little contradictory, could you explain? Commented Apr 2, 2020 at 16:32

2 Answers 2

1

Yeah you can do it like this:

const WizardView = () => {
  return (
    <Wizard finishButtonClick={value => anotherFunction(value)} />
  );
};

Or as follows if you'd prefer:

const WizardView = () => {
  function handleClick(value) {
    anotherFunction(value)
  }

  return (
    <Wizard finishButtonClick={handleClick} />
  );
};
Sign up to request clarification or add additional context in comments.

Comments

0

You can set the return value in state and use it in another function

import React, {useState} from 'react'

const WizardView = () => {
 const[finishVal,setFinishVal]=useState()
  const finishbuttonclickfunction=()=>{
    //set the return value in state
    setFinishVal('function return value')
}
anotherFunction(finishVal){
  //you can use the return value here
}
  return (
    <Wizard finishButtonClick={(val) => finishbuttonclickfunction(val)} />
  );
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.