score:0

while you could use some lifecycle method or the useeffect hook to achieve what you want to do, i would rather use a functional approach.

in your example, finaldata is a derived value of props.data and props.selectedmonth. you could then compute finaldata directly from these props:

const mycustomtable = props => {
    const {
        data = [],
    } = props;

    const filterdata = (data, selectedmonth) => data.map(datapoint => ({
        ...datapoint,
        selected: datapoint.month === selectedmonth,
    }); // or whatever, use your function logic here

    const finaldata = filterdata(data, props.selectedmonth.value);

    return (...);
};

if you really needed to call a function each time data is changing (ex. to fetch data elsewhere) you could use something like that:

const mycomponent = ({ data }) => {
    const [finaldata, setfinaldata] = usestate([]);

    const myfunction = () => {
        const newdata = ... // whatever you need to do
        setfinaldata(newdata);
    };

    useeffect(myfunction, [data]);

    return ...;
};

Related Query

More Query from same tag