This file contains 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
import { useEffect, useRef, useState, Dispatch, SetStateAction } from "react"; | |
/* originally via: | |
https://gist.github.com/AlpacaGoesCrazy/25e3a15fcd4e57fb8ccd408d488554d7 | |
*/ | |
const useStateSafe = function<T>(initialValue: T): [T, Dispatch<SetStateAction<T>>] { | |
const isMounted = useRef(false); // useRef to memorize if the component is mounted between renders | |
const [state, setState] = useState<T>(initialValue); |
This file contains 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
var mongoose = require('mongoose'); | |
var CompanySchema = new CoreRecord({ | |
name: String, | |
ips: [String] | |
}); | |
CompanySchema.method 'reports', function(cb){ | |
mongoose.model('Report').find({companyId: this._id}, cb); | |
}; |