score:2
Accepted answer
another possible solution, is to use context
api.
// steppercontent.jsx
...
export const steppercontentcontext = createcontext();
export const usesteppercontent = () => usecontext(steppercontentcontext);
export const steppercontentprovider = ({ children }) => {
...
const value = { activestep, handlenext, handleback, handlereset };
return (
<steppercontentcontext.provider value={value}>
{children}
</steppercontentcontext.provider>
);
};
so instead of using steppercontent
, you can now use usesteppercontent
hook.
// horizontalformstepper.jsx
...
import {
getstepcontent,
getsteps,
usehorizontalstyles,
usesteppercontent
} from "./common/steppercontent";
const horizontalformstepper = () => {
const classes = usehorizontalstyles();
const {
activestep,
handlereset,
handleback,
handlenext
} = usesteppercontent();
...
might be overkill, but it's there.
Source: stackoverflow.com
Related Query
- How to sync components sharing state hook in React
- How to reinitialize the state with react hook when rerender the components
- How to sync props to state using React hooks : setState()
- How to make sure a React state using useState() hook has been updated?
- how to update multiple state at once using react hook react.js
- How to communicate UI state changes between React components with Redux?
- How to keep React components state after browser refresh
- How to use React Context with useState hook to share state from different components?
- React newbie: sharing state across unlinked components
- How to update (re-render) the child components in React when the parent's state change?
- How to test react components with mobx observable state
- How do I sync state from the DOM to my React Component in an Isomorphic Application?
- How to optimize React components with React.memo and useCallback when callbacks are changing state in the parent
- How does React re-use child components / keep the state of child components when re-rendering the parent component?
- Sync queryParameters with Redux state and react router for function components
- How to keep the React state in sync with MySQL database
- How to reset React hook state with setTimeout in useEffect
- How to check if state default boolean false is changing to true with React Hook useEffect
- React - How do i force child components to re render when parent state component changes?
- How does React State Hook gets the state variable name from the ES6 Destructuring Assignment
- how to fix hook to set state in React JS?
- How to properly update an array inside a react hook state
- How to sync React Router Params with state
- how to calculate default value for react js state hook with a function?
- How to update State Hook with onClick listener on React Component Instance
- How to delete objects from react state hook array with a button click
- How do I fire React useEffect hook only once after state change?
- How to transfer state between React components with hooks?
- How to use map function on react state hook
- How to pass react hook state to another component for each click
More Query from same tag
- Restructuring this JSON data to be tranformed to a barchart data
- React Router 4 links are working but components are not rendered
- Dynamically adding Input form field issue reactjs
- What is a proper way of defining side effects in action(not async thunks) when using redux toolkit?
- 'Expected to return a value at the end of arrow function' - Is there another way to do this other than filter?
- How to pass value from parent component to child component (react)
- How to call react function on click event of react apex chart
- React-cookie: Invariant Violation: The root route must render a single element
- After Delete Mutation not Refetching Query (Apollo Graphql & Nextjs)
- Unexpected token errors when running npm test- Config Error?
- checking array if has same value
- How to extend React component class created via React.createClass
- How to get the text from a child tag onChange on the parent tag?
- Using setInterval in promise chain which uses Redux-Thunk async action
- Why $ is a String and not Identifier in React Js
- Toggle twice to open and close the sidebar menu
- Override Box component in createTheme
- How to render formatted text in ReactJS webapp?
- My updated data does not reflect in even it is status 200
- How to read/understand the nested ternary values in a json object
- Type Error. Cannot react property '0' undefined
- Type '(props: Props) => Element' is not assignable to type 'FunctionComponent<FieldRenderProps<any, HTMLElement>>' with React-final-form
- How to render component as soon as the value stored in local in React
- problem with toggling active class between components in reactJS
- Updating useState returning empty array
- how do i get the link from my uploaded file to firebase to pass to img element?
- Reactjs onMouseOver and onMouseOut event loop in a try for Popover
- props.history not found when using withRouter
- Objects are not valid as a React child (found: [object Promise]) Google Maps
- ReactJS - Navbar Logic Issue