React this.setState is not a function

The callback is made in a different context. You need to bind to this in order to have access inside the callback: VK.api(‘users.get’,{fields: ‘photo_50’},function(data){ if(data.response){ this.setState({ //the error happens here FirstName: data.response[0].first_name }); console.info(this.state.FirstName); } }.bind(this)); EDIT: Looks like you have to bind both the init and api calls: VK.init(function(){ console.info(“API initialisation successful”); VK.api(‘users.get’,{fields: ‘photo_50’},function(data){ … Read more

React Router v4 – How to get current route?

In the 5.1 release of react-router there is a hook called useLocation, which returns the current location object. This might useful any time you need to know the current URL. import { useLocation } from ‘react-router-dom’ function HeaderView() { const location = useLocation(); console.log(location.pathname); return <span>Path : {location.pathname}</span> }

Nested routes with react router v4 / v5

In react-router-v4 you don’t nest <Routes />. Instead, you put them inside another <Component />. For instance <Route path=”/topics” component={Topics}> <Route path=”/topics/:topicId” component={Topic} /> </Route> should become <Route path=”/topics” component={Topics} /> with const Topics = ({ match }) => ( <div> <h2>Topics</h2> <Link to={`${match.url}/exampleTopicId`}> Example topic </Link> <Route path={`${match.path}/:topicId`} component={Topic}/> </div> ) Here is a … Read more

Typescript input onchange event.target.value

Generally event handlers should use e.currentTarget.value, e.g.: onChange = (e: React.FormEvent<HTMLInputElement>) => { const newValue = e.currentTarget.value; } You can read why it so here (Revert “Make SyntheticEvent.target generic, not SyntheticEvent.currentTarget.”). UPD: As mentioned by @roger-gusmao ChangeEvent more suitable for typing form events. onChange = (e: React.ChangeEvent<HTMLInputElement>)=> { const newValue = e.target.value; }

Trying to use fetch and pass in mode: no-cors

mode: ‘no-cors’ won’t magically make things work. In fact it makes things worse, because one effect it has is to tell browsers, “Block my frontend JavaScript code from seeing contents of the response body and headers under all circumstances.” Of course you never want that. What happens with cross-origin requests from frontend JavaScript is that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)