State not updating when using React state hook within setInterval

I’m trying out the new React Hooks and have a Clock component with a counter which is supposed to increase every second. However, the value does not increase beyond one. function Clock() { const [time, setTime] = React.useState(0); React.useEffect(() => { const timer = window.setInterval(() => { setTime(time + 1); }, 1000); return () => … Read more

How to access component methods from “outside” in ReactJS?

Why can’t I access the component methods from “outside” in ReactJS? Why is it not possible and is there any way to solve it? Consider the code: var Parent = React.createClass({ render: function() { var child = <Child />; return ( <div> {child.someMethod()} // expect “bar”, got a “not a function” error. </div> ); } … Read more

Multiple calls to state updater from useState in component causes multiple re-renders

I’m trying React hooks for the first time and all seemed good until I realised that when I get data and update two different state variables (data and loading flag), my component (a data table) is rendered twice, even though both calls to the state updater are happening in the same function. Here is my … Read more

How do you programmatically update query params in react-router?

I can’t seem to find how to update query params with react-router without using <Link/>. hashHistory.push(url) doesn’t seem to register query params, and it doesn’t seem like you can pass a query object or anything as a second argument. How do you change the url from /shop/Clothes/dresses to /shop/Clothes/dresses?color=blue in react-router without using <Link>? And … Read more

Typescript react – Could not find a declaration file for module ”react-materialize’. ‘path/to/module-name.js’ implicitly has an any type

I am trying to import components from react-materialize as – import {Navbar, NavItem} from ‘react-materialize’; But when the webpack is compiling my .tsx it throws an error for the above as – ERROR in ./src/common/navbar.tsx (3,31): error TS7016: Could not find a declaration file for module ‘react-materi alize’. ‘D:\Private\Works\Typescript\QuickReact\node_modules\react-materialize\l ib\index.js’ implicitly has an ‘any’ type. … Read more

Axios get in url works but with second parameter as object it doesn’t

I’m trying to send GET request as second parameter but it doesn’t work while it does as url. This works, $_GET[‘naam’] returns test: export function saveScore(naam, score) { return function (dispatch) { axios.get(‘http://****.nl/****/gebruikerOpslaan.php?naam=test’) .then((response) => { dispatch({type: “SAVE_SCORE_SUCCESS”, payload: response.data}) }) .catch((err) => { dispatch({type: “SAVE_SCORE_FAILURE”, payload: err}) }) } }; But when I try … Read more