I have a function that checks the user's content to see if it matches with any items in the array. Currently, if it matches it automatically replaces the content with a link.
What I'm wanting to do is add an extra step where it asks the user "Would you like to replace this word with a link?".
If it's a match then I'm thinking of adding that match to a new array, and then displaying the array as a card with a "Accept" or "Reject" button. If they hit accept then it will add the link to the content.
The issue I'm facing with the current setup is I can't add anything to the new array in the function, I get the error infinite loop. Any suggestions would be great!
Here's the function code
const generateContent = (content) => {
let final;
if(extraLink == true && word.length > 1){
final = content.replaceAll(word, '<a class="newLink" href=' + link + '>' + word + '</a>');
} else {
final = internalLinks.reduce((a, b) => {
var reg = new RegExp('('+b.name+')', 'gi');
return a.replaceAll(reg, '<a class="newLink" href=' + b.link + '>' + b.name + '</a>');;
}, content);
}
return final;
};
I've tried adding but no luck
setAllLinks([...allLinks, b.name]);
UPDATE Here is the sandbox link to test how it currently functions. Instead of it automatically adding link, I want it to show a card to Accept or Reject (the base of that functions is "setAllLinks") https://codesandbox.io/s/nifty-cache-gqvoxl?file=/src/App.js
generateContent()could produce an infinite loop. Also, I guess the error is not "infinite loop", but something like too many rerenders from react? Like when you do an unconditionalsetValue()during the render cycle.