Skip to content

Instantly share code, notes, and snippets.

View DeleteWithUseConfirm.js
const DeleteWithUseConfirm = () => {
const [ getConfirmation, Confirmation ] = useConfirm()
const onDelete = async () => {
const status = await getConfirmation('Shall we have dinner together tonight?');
if (status) { //status = true
...We can now do the job of deleting
View useConfirm.js
import React, { useState } from 'react'
import { Grid, Dialog, DialogContent, DialogActions, Button } from '@material-ui/core'
const useConfirm = () => {
const [ open, setOpen ] = useState(false);
const [ resolver, setResolver ] = useState({ resolver: null })
const [ label, setLabel ] = useState('')
View createPromise.js
const createPromise = () => {
let resolver;
return [ new Promise(( resolve, reject ) => {
resolver = resolve
}), resolver]
}
@daveteu
daveteu / midtext.js
Created Aug 27, 2020
Simple way to display text in the middle of 2 horizontal lines in Material-Ui
View midtext.js
import { Grid, Divider, Typography } from '@material-ui/core'
//Could use makeStyles here but it's harder to understand
const MidText = ({text}) => {
return ( <div style={{ padding: '8px' }}>
<Grid container>
<Grid item style={{ flex: 1, display: 'flex', alignItems: 'center'}}>
<Divider style={{ flexGrow: 1 }}/>
</Grid>
@daveteu
daveteu / nodeJSbcrypt.js
Created May 18, 2020
Bcrypt with NodeJS
View nodeJSbcrypt.js
const bcrypt = require('bcrypt');
let passwordHash;
bcrypt.hash('passwordString', 10, function(err, hash) {
passwordHash = hash;
});
bcrypt.compare('differentpasswordString', passwordHash, function(err, res) {
if(res) {
console.log(res) //returns true