I have the following components:
InfoDisplayer:
import React, { Component } from "react";
import Typing from "react-typing-animation";
import AnimeInfo from "./animeInfo";
import OtherInfo from "./otherInfo";
const infos = [AnimeInfo, OtherInfo];
export class InfoDisplayer extends Component {
constructor(props) {
super(props);
this.state = {
currentIndex: 0,
};
this.updateDisplayedInfo = this.updateDisplayedInfo.bind(this);
}
updateDisplayedInfo = () => {
const newState = {
currentIndex: this.state.currentIndex,
};
if (this.state.currentIndex === infos.length - 1) {
newState.currentIndex = 0;
} else {
newState.currentIndex++;
}
this.setState(newState);
};
render() {
const Info = infos[this.state.currentIndex];
return (
<React.Fragment>
<Info />
<Typing onFinishedTyping={this.updateDisplayedInfo} loop>
<Info />
<Typing.Reset count={1} delay={2000} />
</Typing>
</React.Fragment>
);
}
}
export default InfoDisplayer;
AnimeInfo:
import React, { Component } from "react";
export class AnimeInfo extends Component {
render() {
return <span>..watching anime</span>;
}
}
export default AnimeInfo;
OtherInfo:
import React, { Component } from "react";
export class OtherInfo extends Component {
render() {
return <span>..simple test</span>;
}
}
export default OtherInfo;
Info is retrieved by looping into infos array. (This is properly working, see React - Component is not re-rendered when state is changed)
I have followed https://gist.github.com/sebmarkbage/f1f4ba40816e7d7848ad to capitalize Info and make sure it is properly treated as a JSX component.
Typing component is from https://github.com/notadamking/react-typing-animation.
Info is displayed (and swapped) outside Typing but not inside. As Info is swapped, it means updateDisplayedInfo is called, so the Typing.onFinishedTyping is triggered. I don't understand why Info isn't displayed in Typing.
Is it a library related issue?