This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create context with no upfront defaultValue | |
// without having to do undefined check all the time | |
function createCtx<A>() { | |
const ctx = React.createContext<A | undefined>(undefined) | |
function useCtx() { | |
const c = React.useContext(ctx) | |
if (!c) throw new Error("useCtx must be inside a Provider with a value") | |
return c | |
} | |
return [useCtx, ctx.Provider] as const |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Select the max id(or your primary key)-- | |
SELECT MAX(id) FROM *table*; | |
--See if the next value in the sequence is bigger than the max id-- | |
SELECT nextval('*table*_id_seq'); | |
--If it isn't make it bigger. This fixes "duplicate key violates unique constraint" error-- | |
SELECT setval('*table*_id_seq', (SELECT MAX(id) FROM *table*)+1); |