1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

fix useEffect warning

This commit is contained in:
Matthias Kretschmann 2019-09-06 14:48:49 +02:00
parent 955608202d
commit a258f6b94b
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -15,27 +15,26 @@ export default function useIpfsApi(config: {
const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs)) const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs))
const [ipfsError, setIpfsError] = useState(null) const [ipfsError, setIpfsError] = useState(null)
async function initIpfs() {
ipfsMessage = 'Checking IPFS gateway...'
if (ipfs) return
try {
const message = 'Connected to IPFS gateway'
console.time(message)
ipfs = await ipfsClient(config)
console.timeEnd(message)
ipfsMessage = message
const version = await ipfs.version()
ipfsVersion = version.version
} catch (error) {
setIpfsError(error.message)
}
setIpfsReady(Boolean(ipfs))
}
useEffect(() => { useEffect(() => {
async function initIpfs() {
ipfsMessage = 'Checking IPFS gateway...'
if (ipfs) return
try {
const message = 'Connected to IPFS gateway'
console.time(message)
ipfs = await ipfsClient(config)
console.timeEnd(message)
ipfsMessage = message
const version = await ipfs.version()
ipfsVersion = version.version
} catch (error) {
setIpfsError(error.message)
}
setIpfsReady(Boolean(ipfs))
}
initIpfs() initIpfs()
// just like componentWillUnmount() // just like componentWillUnmount()
@ -48,7 +47,7 @@ export default function useIpfsApi(config: {
setIpfsError(null) setIpfsError(null)
} }
} }
}, []) }, [config])
return { ipfs, ipfsVersion, isIpfsReady, ipfsError, ipfsMessage } return { ipfs, ipfsVersion, isIpfsReady, ipfsError, ipfsMessage }
} }