0

When I press the sync button, I need to run the Check Routine function. How can I do this ?

const CheckRoutine = require('../routines/check-at');

export default ({ className }) => (
  <ul className={ `nav flex-column ${className || ''}` }>
    <li>
      <button className="btn btn-primary" 
        onClick={CheckRoutine} >
        <i className="fa fa-refresh"> </i>
        <span>Sync</span>
      </button>
    </li>
  </ul>
);```



check-at:

module.exports = atCheck;
function atCheck() {
  console.log("Cheking...");
}
1
  • What’s the problem? Commented Oct 12, 2021 at 1:30

3 Answers 3

2

If your check Routine is in the same component, you can directly give,

<button className="btn btn-primary" 
        onClick={CheckRoutine} >
        <i className="fa fa-refresh"> </i>
        <span>Sync</span>
      </button>

or If your Check routine is in parent component, you can use call back function inside your component like below.

const CheckRoutine =(event) =>{
event.preventDefault();
props.checkRoutine();
}

<button className="btn btn-primary" 
        onClick={CheckRoutine} >
        <i className="fa fa-refresh"> </i>
        <span>Sync</span>
      </button>
Sign up to request clarification or add additional context in comments.

Comments

1

you can use this,

CheckRoutine.js
const CheckRoutine = e => {
console.log(e)
}
export default CheckRoutine


fileName.js
import CheckRoutine from './CheckRoutine'

export default ({ className }) => (
  <ul className={ `nav flex-column ${className || ''}` }>
    <li>
      <button className="btn btn-primary" 
        onClick={CheckRoutine} >
        <i className="fa fa-refresh"> </i>
        <span>Sync</span>
      </button>
    </li>
  </ul>
);

or you can in single file

const CheckRoutine = e => {
 console.log(e)
}
export default ({ className }) => (
  <ul className={ `nav flex-column ${className || ''}` }>
    <li>
      <button className="btn btn-primary" 
        onClick={CheckRoutine} >
        <i className="fa fa-refresh"> </i>
        <span>Sync</span>
      </button>
    </li>
  </ul>
);

Comments

0
import atCheck from '../routines/check-at'

export default ({ className }) => (
<ul className={ `nav flex-column ${className || ''}` }>
    <li>
      <button className="btn btn-primary" 
        onClick={atCheck} >
        <i className="fa fa-refresh"> </i>
        <span>Sync</span>
      </button>
    </li>
  </ul>
);

//../routines/check-at

export default const atCheck => (e) {
  console.log("Cheking...");
}

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.