score:0
what you need to do is called lift the state up (but in your case, is not the state, is a function)
what you could do is
function wrappercomponent(){
const getmenudata = (action) => {...}
return (
<>
<mainmenu getmenudata={getmenudata} />
<home getmenudata={getmenudata} />
</>
)
}
or
if getmenudata
is a function that only depends on it's arguments, you could just put it in another file and import it to both components.
score:1
if the function doesn't use any state manipulation you can just take it out of the component and export it
Source: stackoverflow.com
Related Query
- How to pass function into non related component
- How to pass a function into another component in react
- React: How to pass the data from function located on the child component into parent component?
- how do I pass additional props into a react component through a higher order function
- How do I pass a useState function into a component from context?
- How to pass in a react component into another react component to transclude the first component's content?
- How to pass a function as an argument to a ReactJS component in TypeScript
- Jest/Enzyme Unit Testing: How to pass store to shallow component that uses redux 4 and react-redux 6 connect function
- How to pass function as props from functional parent component to child
- How to pass values from a component into Formik multi-step form wizard?
- How to pass server data into React component
- How to pass function as props from one functional component to another?
- How To Pass Props To Function Component use react-router-dom v6
- How to pass arguments to function in functional component in React
- How to pass graphQL query variable into a decorated react component
- How to pass function from parent component to child component with type assingable
- How to pass return passed data back into a component to display in html
- how to set react parent component state by a async function and then pass this state to child as props?
- How to pass a function as props when both Parent and Child component also a functional component?
- How to pass a wrapped component into React Router without it constantly remounting
- How do I pass a value from an array defined in state into a component which beholds a component?
- How to store react component in state and pass a callback function
- How Do I Pass a Function Through A React Component For Data Sharing Between Parent and Child?
- How to pass route props into my functional component
- How to pass data from a component into getServerSideProps
- How to pass React Component prop to child function using {children}?
- How to pass function from FUNCTIONAL to CLASS component and access it outside of render( without prop ), using context in react js?
- How to fixed error: "You must pass a component to the function returned by connect. Instead received {}", in my React-Redux app?
- How pass a function into an own react context provider which lets you edit the state?
- Need Reactjs help on how to properly pass this function from the parent to child button component
More Query from same tag
- What's the idiomatic way to pass component prop to a component in Vue.js?
- pass props to styled-components selector
- How to render Context Provider and Router separately using functional components?
- How to change React component from outside?
- ScrollSpy with Om
- PropTypes error when using Styled Components
- React-final-form-array how to rerender form based on new state
- Change style of Leaflet CircleMarker's tooltip
- Single-SPA localhost CROS origin Issue- React Application
- slick slider 1 image moves down
- Formik validation not working for my custom react-places-autocomplete component
- Using dotenv module with React
- Loading data into grid on click returns Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'dataState')
- how to add class to an element in a html string in javascript?
- Can't get a json response from my Rails server
- onClick on <li> does't trigger
- Not able to fetch data from node.js API hosted on localhost using ReactJs
- Multi Level JSON Filter
- Can't map data coming from API to render components in React
- How to use normal anchor links with react-router
- How do I mock this method chain in Jest?
- ReactJS not displaying backgroundImage inline CSS
- How to add object to a nested array in mongoDB and nodeJS
- React assinging array vaiable, which one is the best?
- ReactJs Global Helper Functions
- Reactjs : Update value of a component on click
- How can I set scroll to top false only when user clicks back?
- ReactJS: Function run multiple times without being called
- Modifying element in React component after it has rendered
- Dynamic Lazy Loading using React.Lazy (16.6.0)