Hide keyboard in react-native

The problem with keyboard not dismissing gets more severe if you have keyboardType=”numeric”, as there is no way to dismiss it. Replacing View with ScrollView is not a correct solution, as if you have multiple textInputs or buttons, tapping on them while the keyboard is up will only dismiss the keyboard. Correct way is to … Read more

ReactJS – Does render get called any time “setState” is called?

Does React re-render all components and sub-components every time setState is called? By default – yes. There is a method boolean shouldComponentUpdate(object nextProps, object nextState), each component has this method and it’s responsible to determine “should component update (run render function)?” every time you change state or pass new props from parent component. You can … Read more

Error: ‘node-sass’ version 5.0.0 is incompatible with ^4.0.0

TL;DR npm uninstall node-sass npm install sass Or, if using Yarn yarn remove node-sass yarn add sass Edit3: yes, another edit. Moving to sass (dart-sass) is the best solution. Previous one included locking node-sass to version 4.x.x, which is 2 years old and lacks newer SCSS features. Edit2: sass-loader v10.0.5 fixes it. The problem is … Read more

How to specify a port to run a create-react-app based project?

If you don’t want to set the environment variable, another option is to modify the scripts part of package.json from: “start”: “react-scripts start” to Linux (tested on Ubuntu 14.04/16.04) and MacOS (tested by aswin-s on MacOS Sierra 10.12.4): “start”: “PORT=3006 react-scripts start” or (may be) more general solution by IsaacPak “start”: “export PORT=3006 react-scripts start” … Read more

What’s the difference between “super()” and “super(props)” in React when using es6 classes?

There is only one reason when one needs to pass props to super(): When you want to access this.props in constructor. Passing: class MyComponent extends React.Component { constructor(props) { super(props) console.log(this.props) // -> { icon: ‘home’, … } } } Not passing: class MyComponent extends React.Component { constructor(props) { super() console.log(this.props) // -> undefined // … Read more

How to perform debounce?

2019: try hooks + promise debouncing This is the most up to date version of how I would solve this problem. I would use: awesome-debounce-promise to debounce the async function use-constant to store that debounced function into the component react-async-hook to get the result into my component This is some initial wiring but you are … Read more

How to fix missing dependency warning when using useEffect React Hook

If you aren’t using fetchBusinesses method anywhere apart from the effect, you could simply move it into the effect and avoid the warning useEffect(() => { const fetchBusinesses = () => { return fetch(“theURL”, {method: “GET”} ) .then(res => normalizeResponseErrors(res)) .then(res => { return res.json(); }) .then(rcvdBusinesses => { // some stuff }) .catch(err => … Read more

What is the difference between using constructor vs getInitialState in React / React Native?

The two approaches are not interchangeable. You should initialize state in the constructor when using ES6 classes, and define the getInitialState method when using React.createClass. See the official React doc on the subject of ES6 classes. class MyComponent extends React.Component { constructor(props) { super(props); this.state = { /* initial state */ }; } } is … Read more

What is the difference between state and props in React?

Props and state are related. The state of one component will often become the props of a child component. Props are passed to the child within the render method of the parent as the second argument to React.createElement() or, if you’re using JSX, the more familiar tag attributes. <MyChild name={this.state.childsName} /> The parent’s state value … Read more

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