ide-context.js 701 B

123456789101112131415161718192021222324252627282930
  1. import { createContext, useContext } from 'react'
  2. import PropTypes from 'prop-types'
  3. const IdeContext = createContext()
  4. IdeContext.Provider.propTypes = {
  5. value: PropTypes.shape({
  6. $scope: PropTypes.object.isRequired,
  7. }),
  8. }
  9. export function useIdeContext() {
  10. const context = useContext(IdeContext)
  11. if (!context) {
  12. throw new Error('useIdeContext is only available inside IdeProvider')
  13. }
  14. return context
  15. }
  16. export function IdeProvider({ ide, children }) {
  17. return <IdeContext.Provider value={ide}>{children}</IdeContext.Provider>
  18. }
  19. IdeProvider.propTypes = {
  20. children: PropTypes.any.isRequired,
  21. ide: PropTypes.shape({
  22. $scope: PropTypes.object.isRequired,
  23. }).isRequired,
  24. }