score:4
Accepted answer
that's the problem.
this.state = {
currentindex: parseint((math.random()*10))%5,
};
this will be invoked on a server and in the browser causing a mismatch in rendered markup.
you could fix that by making sure random will only be called in a browser:
this.state = {
currentindex: 0,
};
componentdidmount(){
this.setstate({ currentindex: parseint((math.random()*10))%5 })
}
score:0
Source: stackoverflow.com
Related Query
- Incorrect rendering of a component when using Math.random in setState in React Component
- Prevent react component from rendering twice when using redux with componentWillMount
- React component not rendering when using react-rails gem
- React component rendering twice when using useState hook
- react router not rendering the component when using redux
- Why is my react component not rendering only when using routes? react-router-domV.6
- React Router Render props is not rendering component when using params
- Component Not Rendering Properly in React when using CSS hover pseudo selector
- Rendering props to Wrapped Component when using HOC in react
- React "Cannot update a component (`BrowserRouter`) while rendering a different component" warning when registering a new user using firebase
- React changing useState not rendering component when using map to generate elements
- How to prevent child component from re-rendering when using React hooks and memo?
- How to pass the match when using render in Route component from react router (v4)
- React Redux - How to dispatch an action on componentDidMount when using mapDispatchToProps in a connected component
- How to notify parent component of property change when using react hooks?
- React context doesn't transfer when using a component as prop
- Passing setState to child component using React hooks
- React Parent Component completely reconstructed when using Redirect
- React 16: Call children's function from parent when using hooks and functional component
- How can I spread props to a React component that uses exact props when using Flow?
- How should unsubscribe be handled in a react component when using redux?
- Why do my styled component keyframes error with ts-styled-plugin(9999) in react when using percentage instead of TO/FROM
- When do i need to pass prop to constructor of a react component using super(props)?
- Getting the ref from a dynamic component when using Redux, React and react-router-dom 4.x
- How do I check if user is 'logged in' in a react component when using laravel authentication?
- React - setState not re-rendering page when Axios call in separate component
- How to solve closures issue when using React functional component with React.memo?
- Rendering a React component using ES generator
- How to attach a compound component when using React forward ref (property does not exist on forwardRefExoticComponent)
- Rendering a component using a variable in React
More Query from same tag
- React with TypeScript - Type {...} is not assignable to type 'Readonly<S>'
- how to set environment variable from terminal in windows
- 'window is not defined' error when using style-loader with webpack
- How do I un-render a component after routing it to another component in ReactJS?
- Handle iframe in React with refs
- How to render svg icons in react
- Google analytics with react is not working
- How to add two arguments using Typescript Generics in Arrow Function
- Compound Component for Storybook Reactjs
- Casting types in a switch
- React use different value of input field than it is showing
- Converting array of strings to both JSX Elements and strings in React
- Create a counter for .map that persists across component mount/unmount
- Where does one hold service instances in a react/redux application?
- How to best to listen for POST response in react?
- Single SCSS rule showing 'undefined' on server but works in localhost
- Code splitting application sections via dynamic imports
- Context is updating state but on the second try
- react exclude config files from build
- How can I use create-react-app for React version 16.x.x with TypeScript?
- Testing React Components setState overload which takes a function
- How to build a React app whit only a few public routes?
- React update intl dont work: Uncaught ReferenceError: Could not find Intl message:
- How to programmatically navigate to other page in Next.js?
- Making a one time API call by removing the map function
- How can I set react Hooks to another value when it is already set
- How to pass props to components in React js
- Allow arbitrary data-* attributes on React component with Typescript
- React does not recognize the `justifyContent` prop on a DOM element
- i18next react Trans component - escaping characters correctly