profile
viewpoint

Ask questionsWork with react native

Hi,

Any idea how to make this work with react native? I tried node-libs-react-native and rn-nodeify to supply the necessary node libraries but I can't source Block via import {Block} from '@ipld/block' and then calling it like solet block = Block.encoder({hello: 'world'}, 'dag-cbor'); to work: TypeError: undefined is not an object (evaluating '_block.Block.encoder')

Though if I implement it like so I get a dif undefined error:

    const Block = require('@ipld/block');
    let block = Block.encoder({hello: 'world'}, 'dag-cbor');
    let cid = await block.cid()
    console.log(cid);

gives: TypeError: undefined is not an object (evaluating 'crypto.subtle.digest')

ipld/js-block

Answer questions rvagg

Sorry, I don't think we have anyone with any experience with React Native. My guess is that it's a conflict between being treated as a browser vs Node and there's a mixup in that process somewhere.

I'd say your first problem is arising out of https://github.com/ipld/js-get-codec which has different bundling rules for the browser vs Node.js. You may need to manually insert the codec you want rather than letting it choose for you.

The second, probably https://github.com/multiformats/js-multihashing-async, which also has browser-specific rules that may need to be overiden (see package.json#browser which diverts sha to browser code that uses crypto.subtle which isn't available in Node.js).

useful!

Related questions

No questions were found.
Github User Rank List