Hi all,
Iām playing around with JS-IPFS for the first time.
I was experimenting with whether or not I could save my react applications state to ipfs in the way I currently do to localstorage.
Hereās what Iāve tried (which is not working).
componentDidUpdate(){
//here's how i current save state to localStorage
localStorage.setItem("gobitsState", JSON.stringify(this.state))
//here's how I was trying to repeat that for ipfs
const node = new IPFS();
node.once('ready', () => {
console.log("ipfs node is ready");
});
const stateData = JSON.stringify(this.state);
node.files.add(Buffer.from(stateData), (err, res) => {
if (err || !res) {
return console.error('ipfs add error', err, res)
}
})
}
Iām still struggling with the js-ipfs documentation, so Iām not sure if this is correct.
At present Iām getting the following error:
index.js?0bef:64 Uncaught TypeError: Cannot read property 'put' of undefined
at BlockService.put (index.js?0bef:64)
at waterfall (index.js?8d96:400)
at nextTask (waterfall.js?f8db:16)
at next (waterfall.js?f8db:23)
at eval (onlyOnce.js?425d:12)
at Object.serialize (util.js?3584:34)
at waterfall (index.js?8d96:399)
at nextTask (waterfall.js?f8db:16)
at exports.default (waterfall.js?f8db:26)
at IPLDResolver._put (index.js?8d96:398)
The error in index.js64 is:
this._repo.blocks.put(block, callback)
Aside question, do I need to make sure to āendā the node connection once iāve saved the state? How do I do that.
Any advice to point me in the right direction is much appreciated.