Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Is there a higher order function to avoid fire on render?

I have a function

const onClick = (param) => console.log(param)

and need to use it like:

<Button onClick={onClick(value)} />

But it fires on render, how I can change function into higher order function to use it like that?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Not sure where value is coming from but like this?

<Button onClick={() => onClick(value)} />

Which could be shifted to

const logOnClick = (msg) => () => console.log(msg);

<Button onClick={logOnClick(value)} />
about 4 years ago · Juan Pablo Isaza Report

0

You can try this

import React from 'react';
import './style.css';

export default function App() {
  const Ho = (data) => {
    return () => {
      console.log('Something');
    };
  };

  return (
    <div>
      <h1>Hello StackBlitz!</h1>
      <p>Start editing to see some magic happen :)</p>
      <button onClick={Ho('data')}> Click</button>
    </div>
  );
}

Link -https://stackblitz.com/edit/react-mxcbvq?file=src/App.js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!