I'm using Anime.js to do some animation on a site I am building. Right now I am trying to animate a string of a few words.
I have the animation working and everything with Anime.js is working fine. The problem I am having is that I want to store the words I am animating in my React component's state like this:
this.state = {
heading: "Hudson Valley Web Design"
}
As you can see my heading consists of several words with spaces. I implement the Anime.js effects by iterating over this.state.heading like this:
<h1 className="ml9">
<span className="text-wrapper">
{Object.values(this.state.heading).map((letter) => {
// This regular expression that checks for spaces isn't
// working
if(letter === /\s/g.test(letter)) {
return <span className="letters">" "</span>
}
return (
<span className="letters">{letter}</span>
);
})}
</span>
</h1>
The effect works properly but all the words are squished together i.e. "HudsonValleyWebDesign". How can I detect white spaces in this.state.heading inside my Object.keys function and put spaces between each word?
Also, for clarification, I need the individual letters to be in span tags for the sake of applying the CSS for the Anime.js functionality.
" "be or so?HudsonValleyWebDesign. I assume the behaviour that the OP describes is specific to Anime lib.