pagination + sql expressions + frontend improvements
This commit is contained in:
21
react/shared/hooks/current-path.js
Normal file
21
react/shared/hooks/current-path.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import {useLocation, useParams} from "react-router-dom";
|
||||
|
||||
|
||||
export default function useCurrentPath() {
|
||||
const location = useLocation();
|
||||
const params = useParams();
|
||||
|
||||
const { pathname } = location;
|
||||
|
||||
if (!Object.keys(params).length) {
|
||||
return pathname; // we don't need to replace anything
|
||||
}
|
||||
|
||||
let path = pathname;
|
||||
Object.entries(params).forEach(([paramName, paramValue]) => {
|
||||
if (paramValue) {
|
||||
path = path.replace(paramValue, `:${paramName}`);
|
||||
}
|
||||
});
|
||||
return path;
|
||||
}
|
||||
Reference in New Issue
Block a user