score:0
you will have to wait for ongridready before you can call gridapi.current.setfiltermodel(defaultfilter)
. then only you will have non-undefined gridapi.current
.
so, instead of running gridapi.current.setfiltermodel(defaultfilter);
inside an useeffect, rut it in a callback in parent
and pass that callback to child mygrid
example code:-
function parent() {
const defaultfilter = {
transactionid: {
filtertype: "number",
type: "equals",
filter: 1111
}
}
const gridapi = useref();
const setparentfiltermodel = () => { // <== callback function to be called on ongridready
gridapi.current.setfiltermodel(defaultfilter);
};
return (
<div>
<mygrid forwardedref={gridapi} setparentfiltermodel={setparentfiltermodel}/> {/* <== pass callback function to child */}
</div>
);
}
function mygrid(props) {
const gridapi = useref();
const ongridready = params => {
gridapi.current = params.api;
if (props.forwardedref) {
props.forwardedref.current = params.api;
props.setparentfiltermodel() // <== call callback function
}
};
}
Source: stackoverflow.com
Related Query
- Run useEffect when ref.current is assigned a value
- React: why is that changing the current value of ref from useRef doesn't trigger the useEffect here
- React Hook useEffect has a missing dependency when updating state based on current value
- Why does my useEffect react function run when the page loads although I am giving it a second value array
- When using custom hook how do I get the current value before useEffect call?
- When value is assigned to components state, why console.log prints the previous state?
- useEffect not working when dependency value changed
- ReactJS: useEffect is not run when the url changes
- what's the advantage of using ref versus id when referencing the input value
- Mocking current value of react ref in jest for shallow test
- Why ref value is correct in useEffect but nullish in component body
- How to only run useEffect when something was added to array with React?
- How to useEffect when value in localStorage changed?
- How can I use useEffect in React to run some code only when the component first mounts, and some other code whenever an event occurs (repeatedly)?
- React.StrictMode: SetState function in useEffect is run multiple times when effect is run once
- ReactJS how to run an API call when a state has a particular value
- React hooks - how to force useEffect to run when state changes to the same value?
- Inifnite render error when setting value via useState inside a useEffect only when testing
- useEffect throws an error when used to set input value
- How to execute useEffect hook callback only when a single value from the hook callback changes?
- Run function in useeffect when state changes after 1 second if no other changes
- My variable has not updated yet when I create my onClick function since useEffect is run last
- Run CSSTransition inside TransitionGroup when any value changes
- How can I let the useEffect run only when its parameter change?
- Getting current value of variable outside the useEffect in React
- State variable inside a function defined within useEffect hook is not updating when value changes
- I can't get the current state value in `beforeunload` event when refresh the page?
- How can I set default value after actions in useEffect when I use custom hooks
- Is there a way in React.js to run a side effect after `useState` when the value of the state doesn't change in functional components?
- Do I have to use ref when passing current DOM-element?
More Query from same tag
- How can i display flags as option in a select
- Error in App class when using React-Redux "connect "
- Store item to local storage after adding a new item using redux toolkit
- How to create a button component inside of a react-router Link that does not redirect?
- Focus Editor, Position Cursor at Start of First Block
- getInitialProps import data in Next.js
- How do i prevent formik yup ( regex ) validation from disappearing
- Exclude laravel route using wildcard
- Go Restful API : CORS configuration works with React but not with Angular
- React can't deconstruct restProps in Edge
- State is not getting updated
- When react application is in production, while refreshing the same routes browser shows 404 error but not in localhost
- Is it possible to import wildcard path in React Typescript?
- Module parse failed: Unexpected token. Cannot load img tag
- React.js: how does updating dynamic subcomponents work?
- Error with React render
- Firestore pagination with react-redux
- Can I use state AND props for control between parent/child
- progress[value] style with react
- Updating the Chloropleth Tutorial to react-leaflet v3 With Function React Components
- How to hide the tooltip after certain time
- How do I combine useLocation() with useSelector()?
- React + Redux: Component does not update
- Apply a class to table row when checkbox is checked using states
- Routing with Iterating list in react js
- Does change in Props Data Change the state of components or will it render the change?
- Conditionally pass a Boolean prop with a dynamic prop name to a React component
- How to stop making api call on re-rendering in React?
- Async action not adding data to Redux store in time leading to, Error: Cannot read property 'map' of undefined
- React.js - Use cdn methods