Loading non-media assets (markdown)

I’m also trying to use local Markdown assets and prioritize first-load-offline support.

This seems to work on both iOS and Android devices in Expo client

import { FileSystem, Asset } from 'expo'

// ...

const getMarkdown = markdownId => {
  const markdownAsset = await Asset.fromModule(require(`./assets/markdown/${markdownId}.md`))
  const markdown = await FileSystem.readAsStringAsync(markdownAsset.localUri)
  return markdown
}

getMarkdown(`filename`)

app.json excerpt

"packagerOpts": {
  "assetExts": [
    "md"
  ]
},
"assetBundlePatterns": [
  "assets/**/*"
]

Here’s a related snack I was working on.

Hope that helps, and would love to know if you have found some other approach.

1 Like