You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
planka_custom/client/src/hooks/use-steps.js

27 lines
509 B
JavaScript

import { useCallback, useState } from 'react';
const createStep = (type, params = {}) => {
if (!type) {
return null;
}
return {
type,
params,
};
};
export default (initialType, initialParams) => {
const [step, setStep] = useState(() => createStep(initialType, initialParams));
const open = useCallback((type, params) => {
setStep(createStep(type, params));
}, []);
const handleBack = useCallback(() => {
setStep(null);
}, []);
return [step, open, handleBack];
};