score:1
You can store the index in a state, and use setTimeout
to update that state every 10 seconds.
You only want to call this.instantiatePanels()
once, so do that before the render
and save the results, then in the render
index that saved array using the index from the state.
Also, if the Panel-instantiation is as simple as in your snippet, I would avoid the instantiation entirely, and instead have a render function like:
render() {
return (
<div className="App">
<Panel data={this.state.data} currentPanel={panelIndexState} key={this.state.data.Key} />
</div>
);
}
And in the component, before the render, define something like:
const iteratePanelIndex = () => {
this.setState((state) => {
...state,
panelIndexState: (state.panelIndexState +1) % 7
})
setTimeout(iteratePanelIndex, 10000);
};
(depending on how you're handling state)
Then call iteratePanelIndex()
in componentDidMount
to kick things off
Source: stackoverflow.com
Related Query
- How can I render through similar components on a timer?
- How can I render multiple components while looping through an object and then interpolate the JSX associated?
- How I can render react components without jsx format?
- How I can loop through the similar objects in state and push them into object?
- React: How can I dynamically render images mapping through a list?
- How to use React + TypeScript to render components by looping through an array?
- How can I render multiple components interpolating JSX?
- How can I render the components after useEffect hook is finished?
- How can I render an array of components in react without them unmounting?
- How can I render different news components into the Navbar Component & display their data on the Navbar page, On Click of Navbar menu links
- How can I iteratively render nested components in react?
- How can I render multiple components from a single route change?
- How can I conditionally render different components on initial load in React?
- After being able to load the landing page(Home component) , how do you get the rest of the react components to render through github pages?
- How can I render out a piece of content dynamically only once from mapped through data, despite potentially multiple matches?
- How can I dynamically render components when enter an input
- How can I return my data string through a dangerouslyHTML function in order to render out bold tags?
- How can I make my React child components render even if a prop is missing
- How can I use state to render form components in React?
- how can i loop through the array inside of an object. and render it in the react component
- How to render FluentUI controls in a HTML page similar to rendering React Components in a script tag inside a Div
- How can I pass through some props to other components in reactjs?
- How can I prevent event bubbling in nested React components on click?
- How to render react components by using map and join?
- How can I render repeating React elements?
- How can I render HTML from another file in a React component?
- How can I map through an object in ReactJS?
- how to render child components in react.js recursively
- How can I parse through local JSON file in React js?
- Facebook React.js: how do you render stateful components on the server?
More Query from same tag
- How would I pass info between two functions
- TypeError: Class extends value undefined is not a constructor or null (React Meteor Data)
- React router, pass props with Link
- Should Promises be avoided in React components?
- I am getting error in console "You need to enable JavaScript to run this app." reactjs
- CSS diagonal gradient with a more smooth transit
- React Redux - passing arguments to event handler not working
- How can I push value to url in react js?
- How to setState() from within a nested function in React?
- Cannot read property '_resetForm' of undefined
- How do I add multiple values to a dynamic table in react?
- passing a variable from child component to parent component in Next.js
- Cant use CSS and justify content on react Bootstrap
- TypeError: (0 , _schemaUtils.default) is not a function
- Converting React component to a single js file to integrate it with a blank html
- React refactor componentDidMount() to call function
- Want to present each time the values I have reached
- React js setstate not working in nested axios post
- Change material of gltf-imported mesh programmatically - react three fiber
- How to center view to new Markers with useMapEvents?
- useState variable is one step behind its assignment
- "getFirebase() is not a function" after running npm install
- change width of NeWindow using react-new-window react
- here is problem for installing the styled-components from npm?
- Redux + NodeJS + Axios + Twitter API error? No 'Access-Control-Allow-Origin' header
- im recieving a empty json object
- Dynamic Width Measurement: ReactJS/NodeJS & HTML/CSS
- Conditionally return ForwardRefExoticComponent and FunctionalComponent
- How to fix this Error:Uncaught TypeError: Cannot read properties of undefined (reading 'params')
- Why am I getting a 500 error on form submit?