I am having an issue with extracting a number from a string in react. The solution I used works fine on the local machine but doesn't work as required when push into production. I tried on netlify and heroku but getting same result.
I fetch the data from a text file which has a list of content and further detail for each of the heading. Link to the text file is here: Link to text file from where I am fetching the data
For example:
- Game Concepts 100. General 101. The Magic Golden Rules
- Parts of a Card 200. General 201. Name
- Card Types 300. General 301. Artifacts
So, I am separating the main headings i.e. 1. Game Concept, 2. Parts of a Card, 3. Card Types and subheadings i.e. 100. General, 101. The Magic Golden Rules, 200. General, 201. Name, 300. General, 301. Artifacts etc... from that text file.
As I mentioned earlier, the method I tried works fine on local machine but as soon as I push the code to production I get the list as it was earlier + the new list that is separated. I tried this as well:
parseFloat([heading]) + "." < 5 , parseFloat([heading]) < 5
...but didn't get desired results.
I have no idea what to do, I shall be grateful for getting some help on this issue.
Below is App.js:
import { useState, useEffect } from "react";
import url from "./MagicRules.txt";
import "./App.css";
function App() {
let tempdata = [];
let dataSplit = [];
let headings = [];
const [newdata, setNewData] = useState([]);
useEffect(() => {
temp();
// eslint-disable-next-line
}, [0]);
const temp = async () => {
tempdata = await (await fetch(url, { mode: "no-cors" })).text();
dataSplit = tempdata
.split(/^\s+|\s+$/gm)
.filter((element) => isNaN(element));
dataSplit = dataSplit.slice(0, dataSplit.lastIndexOf("Glossary"));
headings = dataSplit.filter((heading) => parseInt([heading]) + "." < 5);
let newHeadings = [...new Set(headings)];
setNewData(newHeadings);
};
return (
<div className="App">
{newdata.map((heading, index) => (
<ul key={index}>{heading}</ul>
))}
</div>
);
}
export default App;