mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-25 20:40:36 +03:00
R: useContext -> use hook
This commit is contained in:
parent
cad521f46d
commit
ef79f3b83e
|
@ -1,6 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { createContext, use, useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
|
||||
export interface NavigationProps {
|
||||
|
@ -23,9 +23,9 @@ interface INavigationContext {
|
|||
setIsBlocked: (value: boolean) => void;
|
||||
}
|
||||
|
||||
const NavigationContext = createContext<INavigationContext | null>(null);
|
||||
export const NavigationContext = createContext<INavigationContext | null>(null);
|
||||
export const useConceptNavigation = () => {
|
||||
const context = useContext(NavigationContext);
|
||||
const context = use(NavigationContext);
|
||||
if (!context) {
|
||||
throw new Error('useConceptNavigation has to be used within <NavigationState>');
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { createContext, use, useEffect, useState } from 'react';
|
||||
|
||||
import { urls, useConceptNavigation } from '@/app';
|
||||
import { useAuthSuspense } from '@/features/auth';
|
||||
|
@ -44,9 +44,9 @@ export interface IOssEditContext {
|
|||
setSelected: React.Dispatch<React.SetStateAction<number[]>>;
|
||||
}
|
||||
|
||||
const OssEditContext = createContext<IOssEditContext | null>(null);
|
||||
export const OssEditContext = createContext<IOssEditContext | null>(null);
|
||||
export const useOssEdit = () => {
|
||||
const context = useContext(OssEditContext);
|
||||
const context = use(OssEditContext);
|
||||
if (context === null) {
|
||||
throw new Error('useOssEdit has to be used within <OssEditState>');
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { createContext, useContext, useState } from 'react';
|
||||
import { createContext, use, useState } from 'react';
|
||||
import { useFormContext } from 'react-hook-form';
|
||||
|
||||
import { useDialogsStore } from '@/stores/dialogs';
|
||||
|
@ -25,9 +25,9 @@ export interface ITemplateContext {
|
|||
onChangeFilterCategory: (newFilterCategory: IConstituenta | null) => void;
|
||||
}
|
||||
|
||||
const TemplateContext = createContext<ITemplateContext | null>(null);
|
||||
export const TemplateContext = createContext<ITemplateContext | null>(null);
|
||||
export const useTemplateContext = () => {
|
||||
const context = useContext(TemplateContext);
|
||||
const context = use(TemplateContext);
|
||||
if (context === null) {
|
||||
throw new Error('useTemplateContext has to be used within <TemplateState>');
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ interface EditorControlsProps {
|
|||
}
|
||||
|
||||
export function EditorControls({ constituenta, disabled, onEditTerm }: EditorControlsProps) {
|
||||
const { schema } = useRSEdit();
|
||||
const schema = useRSEdit().schema;
|
||||
const { isModified } = useModificationStore();
|
||||
const isProcessing = useMutatingRSForm();
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ export function EditorRSExpression({
|
|||
onShowTypeGraph,
|
||||
...restProps
|
||||
}: EditorRSExpressionProps) {
|
||||
const { schema } = useRSEdit();
|
||||
const schema = useRSEdit().schema;
|
||||
|
||||
const [isModified, setIsModified] = useState(false);
|
||||
const rsInput = useRef<ReactCodeMirrorRef>(null);
|
||||
|
|
|
@ -8,8 +8,8 @@ import { colorBgSchemas } from '../../../colors';
|
|||
import { useRSEdit } from '../RSEditContext';
|
||||
|
||||
export function SchemasGuide() {
|
||||
const { items: libraryItems } = useLibrary();
|
||||
const { schema } = useRSEdit();
|
||||
const libraryItems = useLibrary().items;
|
||||
const schema = useRSEdit().schema;
|
||||
|
||||
const schemas = (() => {
|
||||
const processed = new Set<number>();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { createContext, use, useEffect, useState } from 'react';
|
||||
|
||||
import { urls, useConceptNavigation } from '@/app';
|
||||
import { useAuthSuspense } from '@/features/auth';
|
||||
|
@ -66,9 +66,9 @@ export interface IRSEditContext {
|
|||
promptTemplate: () => void;
|
||||
}
|
||||
|
||||
const RSEditContext = createContext<IRSEditContext | null>(null);
|
||||
export const RSEditContext = createContext<IRSEditContext | null>(null);
|
||||
export const useRSEdit = () => {
|
||||
const context = useContext(RSEditContext);
|
||||
const context = use(RSEditContext);
|
||||
if (context === null) {
|
||||
throw new Error('useRSEdit has to be used within <RSEditState>');
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export function ConstituentsSearch({ dense }: ConstituentsSearchProps) {
|
|||
const setSource = useCstSearchStore(state => state.setSource);
|
||||
const toggleInherited = useCstSearchStore(state => state.toggleInherited);
|
||||
|
||||
const { schema } = useRSEdit();
|
||||
const schema = useRSEdit().schema;
|
||||
|
||||
return (
|
||||
<div className='flex border-b clr-input rounded-t-md'>
|
||||
|
|
Loading…
Reference in New Issue
Block a user