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.
27 lines
509 B
JavaScript
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];
|
|
};
|