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 ...;
};
Source: stackoverflow.com
Related Query
- Trigger Child component method when prop changes
- React: why child component doesn't update when prop changes
- Child component does not rerender when parent changes prop
- React child component does re-render when prop changes value
- Re-render React component when prop changes
- How to re render parent component when anything changes in Child Component?
- render react component when prop changes
- React: Trigger method in child component from different child component
- How to Prevent Child Component Re-Render when Parent state changes
- Using React Hooks, when I pass down a prop from parent to a child component, the prop in the child component is undefined
- How do I pass a prop to a react component yet not update that prop in the child when parent changes?
- Child Component doesn't rerender when state of parent component changes
- React not rerendering the component when prop changes
- `this` being undefined on object method when called as a react component prop
- Call component method when model property changes
- Change prop of child component when s
- React: Hook not triggering when parent component changes boolean value passed to child
- Reactjs - update child component state when parent component state changes
- React - Where to unit test state change when parent component passes method as prop: parent or child component?
- React App class won't render when a child Component changes
- React - Best way to trigger a child method from parent/sibling component
- connect not change the props of child component when the prop object modified
- Inputs in child component won't update when prop is changing in parent component
- update child component when parent component changes
- React update parent component when child changes the Context
- How to have React re-render a functional component when prop changes
- How can I force a component to "reset" when a prop changes in React?
- Function passed via a prop to child component is not a function when called
- React: how to use setState and render component when prop changes
- Rerender functional component when prop changes
More Query from same tag
- ReactJS Is it adviceable to update props
- Problematic webGL support in electron
- react useState not working with new Date() as initial value
- ReactJS - Error: Objects are not valid as a React child
- Cannot call setState() when attempting to update list in todo app
- Axios not returning value
- how to use onClick while mapping
- Page reloads after setting state and instead of new state it goes back to initial state
- React Loading a Dynamic Template using JSX & ES6
- How to type link prop in component (React + TypeScript)?
- I want the arrow icon to flip up and down every time the state changes.and I want to animate it
- Get a specific response header (e.g., Content-Disposition) in React from an ASP.NET CORE Web Api
- Arrow function should not return assignment?
- react set state isn't working immediately
- Cant show my features in openlayers. Does someone know how to solve this?
- How to create button with function of draw polygons in Leaflet?
- React state is set function is not working
- Render SVG based on passed property "element"
- Dynamic Forms in React, Cannot read property 'map' of undefined
- Converting react component to pdf with no sucess (html2canvas and dom-to-image)
- How to render an element in a matrix in react?
- How to empty the dropzone after submit reactjs
- How to create line chart with JSON data using D3
- How to share Image-Url to Facebook, twitter and Instagram in React JS
- How to use autoprefixer with ViteJS and React?
- onClick event doesn't work on styled-component but it works on everyother components
- ReactJS confusing 'JS code as text' and real JS code: Add javascript code as text in ReactJS div
- React.js array .push() is taking multiple values
- React dnd to push object of dropped item to component's state.
- React Jest: How to mock Service?