I have the following code:
export function App() {
return (
<div>
<EditText tags={[[["b",28,32]],[["br",40,40]],[["i",43,88],["b",56,64],["b",74,84]],[["b",102,105]]]}/>
</div>
);
}
export const EditText = ({ tags }) => (
<>
{
tags.map((section, id) => {
console.log("id",id);
if (section[0][0] === "i") {
if (id!==0) {
console.log("entering recursion");
return <EditText key={id} tags={section} />
}
}
return("");
})
}
</>
);
To make it more visually, the array looks like this:
[
[["b",28,32]],
[["br",40,40]],
[
["i",43,88],["b",56,64],["b",74,84]
],
[["b",102,105]]
]
I would expect this algorithm to print in the console the ids like this:
0 1 2 0 1 2 3
because the recursion is called after the third sequence in the map. But instead, it's printing this:
0 1 2 3 0 1 2
It's ending the first map and only at the end of it he remembers to call the recursion.
Can anyone explain me why this is happening?