Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Foreach Char in String in nextjs not working

I tried to loop each character in String but SPANS are not rendering. What am I doing wrong?

export default function Work() {
  const logoText =
    "The future starts here.";

  return (
    <div className="absolute w-full h-full">
        {logoText
           .split("")
           .forEach(
             (character, i) =>
               `<span className="rotate-[${
                 i * 8.1
               }deg] absolute left-[50%] text-xl origin-[0px_130px]">${character}</span>`
         )}
    </div>

I also tried with putting only "character" instead of all the span code and it doesnt’ work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

change forEach to map for geting return

try this it work fine:

export default function Work() {
  const logoText =
    "The future starts here.";

  return (
    <div className="absolute w-full h-full">
      {logoText.split('').map((character, i) => (
          <span
            className="rotate-[${
                i * 8.1
              }deg] absolute left-[50%] text-xl origin-[0px_130px]"
          >
            {character}
          </span>
        ))}
    </div>

also you can check live code here: https://stackblitz.com/edit/react-wnwgkt?file=src%2FApp.js

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading