Skip to content

Instantly share code, notes, and snippets.

View dioscarey's full-sized avatar
🎯
Focusing

Oscar dioscarey

🎯
Focusing
View GitHub Profile
// you can create your own path matcher or you can use any url matcher from npm.
const route = require('path-match')({
sensitive: true,
strict: true,
end: true,
});
class YOURMiddleware {
constructor(opts = {}) {
this.stack = []; // Middleware stack
const postFunction = async (ctx) => {
try {
const {id} = ctx.req.body;
const r = await ctx.db.getData(id);
// This respond function is customizable in your middleware
ctx.respond(200, r);
const db = require('./dbConnection');
const putFunction = require('./controllers/putFunction');
const postFunction = require('./controllers/postFunction');
const YOURMiddleware = require('./YOURMiddleware'); // You can create a private package to make it sharable or you can find a way to share your middleware with other functions.
const gcf = new YOURMiddleware()
gcf.context({
db
});
import React from 'react';
import BeforeUnloadComponent from 'react-beforeunload-component';
import MyModal from 'path/MyModal';
// React Hook
const Example = () => {
return (
<div>
<BeforeUnloadComponent
blockRoute={true}
import React from 'react';
import BeforeUnloadComponent from 'react-beforeunload-component';
// React Hook
const Example = () => {
return (
<div>
<BeforeUnloadComponent
blockRoute={true}
/>
const links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
links[i].addEventListener("click", handleClickEvents, false);
}
window.removeEventListener("beforeunload", beforeUnloadFunction);
window.removeEventListener("beforeunload", beforeUnloadFunction);