I'm working on a React project and I want to load some raw (string) Markdown files to an array of objects.
What I want to do - but it doesn't work:
links_file.js
export const links = ["path to file 1.md", "path to file 2.md", ...]
logic.js
import { links } from "links_file.js"
componentDidMount() {
links.map( (link, index) => {
fetch(link).then(resp => {
return response.text()
}).then( text => {
// Make a shallow copy of the files
let files = [...this.state.files];
// Make a shallow copy of the file to mutate
let updatedFile = {...files[index], content: text};
// Make a shallow copy of the item to mutate and replace the property
files[index] = updatedFile;
//Set the state to the new copy
this.setState({files});
})
})
}
Console logging text gives me the index.html instead of the raw md content I want.
This works:
import file1 from 'path to file 1.md';
import file2 from 'path to file 2.md';
componentDidMount() {
fetch(file1).then(resp => {
return response.text()
}).then( text => {
this.setState(file1: text);
})
}

this.state.filesonly filled with 1 of the 2 (or more) results?this.state.files, that an array of objects, the object has a propertycontentwhich I want to set with the raw data from those files.console.log(link, text), it gives you"path to file 1.md", "<!doctype><!-- index.html -->"?