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] | |
} |
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> |
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 |