export const useDuration = () => {
const [p, setParams] = useState({
userLn: 0;
userLg: 0;
pointLn: 0;
pointLg: 100; // несуществующая широта
});
const {isLoading, data: duration, error, refetch} = useQuery(
["get duration", p],
() => GetDuration.getByCoordinates(p.userLn, p.userLg, p.pointLn, p.pointLg),
{
enabled: p.pointLg <= 90 // проверяем, что параметры заданы
}
);
return {isLoading, duration, error, refetch, setParams};
};
......
const {..., setParams} = useDuration();
......
...onClick={() => setParams(...)}
/** Field input value, name, and event handlers */
export interface FieldInputProps<Value> {
/** Value of the field */
value: Value;
/** Name of the field */
name: string;
/** Multiple select? */
multiple?: boolean;
/** Is the field checked? */
checked?: boolean;
/** Change event handler */
onChange: FormikHandlers['handleChange'];
/** Blur event handler */
onBlur: FormikHandlers['handleBlur'];
}
import {render} from '@testing-library/react';
import React from 'react';
import type {FieldInputProps} from 'formik';
describe('test group', () => {
it('test', async () => {
const fieldStub: FieldInputProps<string> = {
value: '...',
name: 'name',
onChange: jest.fn(),
onBlur: jest.fn(),
};
const result = render(
<Checkbox field={fieldStub} label={'label'} />
);
expect(...).toBe***(...);
});
});