score:3
Accepted answer
all you need to do is to change this bit in your code:
this.interval = setinterval(() => this.tick('hi'), 1000);
alternatively, you can also send in this
to the callback:
this.interval = setinterval(function(t) {t.tick('hi')}, 1000, this);
see the updated fiddle, here.
setinterval()
takes (at least) two parameters, the first one is the callback and needs to be a function. you had provided the code directly; that code must be inside a function.
var intervalid = scope.setinterval(func, delay);
func
a function to be executed every delay milliseconds. the function is not passed any parameters, and no return value is expected.
score:0
change code to:
componentdidmount: function() {
this.interval = setinterval(()=>this.tick('hi'), 1000);
}
Source: stackoverflow.com
Related Query
- Why does this interval stop ticking in react?
- Why does this error stop the rendering of my react app?
- Why does this official React testing recipe using await/act/async actually work?
- Why does this React component return the string '0'
- Why ES6 ComputedPropertyName does not work with this react js code?
- Why does this create an infinite render loop with React hooks?
- Why does this React App initialize twice?
- why I can't stop interval in react functional component
- Why does React see the old state in this example?
- Why does this react form works only for the first time?
- Why does this React router NavLink either redirect or submit successfully but, not both?
- Why does this custom React hook using useContext useEffect and setInterval fail in test
- Why does this React component return 9 errors
- Why does this React accordion scroll the page up when an element is expanded?
- Why does this method updates react state very slowly?
- Why does this approach to drawing a line in an SVG element in react not work?
- Why does my unit test return 'cannot read property 'simulate' of undefined' in this React test?
- In this basic react application, why does the custom component `TextInput` allow me to type stuff in even though the regular `input` field doesn't?
- Why does putting a div tag allow this React code to compile?
- Why does calling react setState method not mutate the state immediately?
- In React ES6, why does the input field lose focus after typing a character?
- Why does React warn against an contentEditable component having children managed by React?
- Why does React Native not offer a justify-self
- Why does Async Await work with React setState?
- Why does my React Component Export not work?
- React - useState - why setTimeout function does not have latest state value?
- Why does React require Babel and Webpack to work?
- Why does React have a server on its own?
- Why does my React Native app build successfully despite TypeScript compiler error?
- React Native - why padding does not work?
More Query from same tag
- Fulfilled promise stored rather than the request body
- Why isn't the map function iterating over the array?
- NextJS error while trying to navigate to dynamic route
- Filtering an Array with another Array
- Customize datetpicker MUI
- Error text for Components other than TextField and SelectField
- Only display button if there is history
- Ant Design Cards doesn't align properly
- Is there a way to have custom breakpoints in React-Bootstrap
- use react-codemirror2 with functional component
- setState in $.get
- React-Router 1.0 alternative to Router.HistoryLocation
- Material UI Dark Mode
- Is there a way to get the count of filtered options in react-select?
- How to get a new array from an array with nested objects?
- How to get scrollPosition using getSnapshotBeforeUpdate() in React Js?
- What is wrong with this CodePen?
- Handle void method as object's property in React, redux, typescript
- Type conversion with flow
- Why This Css Class Condition not work in react js?
- Test suite failed to run. Invariant Violation: _registerComponent(...): Target container is not a DOM element
- GlobalHotKeys(react-hotkeys) not working when focused on the input field
- Correct way to catch fetch errors in React?
- useState asynchronous problem with select
- React - Infinite loop when changing state from onChange
- Why does state object exist in React?
- how to get the result from recursive promises in a redux action
- React: What Controls Value of this.props.loading?
- React Router - hide header and footer when rendered in iFrame
- ReactRouter: How to access route params in component