@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
28 lines • 1.08 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { createContext, useContext, useState } from 'react';
const defaultCtx = { state: { view: 'utilities', data: null }, setState: () => { } };
const ViewContext = createContext(defaultCtx);
export const useNavigate = () => {
const { setState } = useContext(ViewContext);
const navigate = (view, data) => {
setState({ view, data });
};
return navigate;
};
export const Route = ({ view, element }) => {
const { state } = useContext(ViewContext);
if (view === state.view) {
if (typeof element === 'function') {
return element(state.data);
}
return React.createElement(React.Fragment, null, element);
}
return null;
};
const Router = ({ children }) => {
const [state, setState] = useState({ view: 'utilities', data: null });
return React.createElement(ViewContext.Provider, { value: { state, setState } }, children);
};
export default Router;
//# sourceMappingURL=router.js.map