React Native – Image Require Module using Dynamic Names

This is covered in the documentation under the section “Static Resources”: The only allowed way to refer to an image in the bundle is to literally write require(‘image!name-of-the-asset’) in the source. // GOOD <Image source={require(‘image!my-icon’)} /> // BAD var icon = this.props.active ? ‘my-icon-active’ : ‘my-icon-inactive’; <Image source={require(‘image!’ + icon)} /> // GOOD var icon … Read more

Typescript + React/Redux: Property “XXX” does not exist on type ‘IntrinsicAttributes & IntrinsicClassAttributes

So after reading through some related answers (specifically this one and this one and looking at @basarat’s answer to the question, I managed to find something that works for me. It looks (to my relatively new React eyes) like Connect was not supplying an explicit interface to the container component, so it was confused by … Read more

JSX or HTML autocompletion in Visual Studio Code

2022: Straightforward way to add JSX/HTML autocomplete for .js files in React projects… First, open VSCode’s settings.json. To open settings.json, press Ctrl + , (or Cmd+, on Mac), then click the Open JSON button shown below. Optionally, if you don’t want to set this globally, you can create a .vscode/settings.json file at the project root. … Read more

Passing object as props to jsx

Is this possible? Yes its possible, but the way you are sending it is not correct. The meaning of <MyJsx commonProps /> is: <MyJsx commonProps={true} /> So if you don’t specify any value, by default it will take true. To pass the object, you need to write it like this: const commonProps = {myProp1: ‘prop1’,myProp2: … Read more

&nbsp jsx not working

See: JSX In Depth Try: Select Scenario:{‘\u00A0’} Or: <div dangerouslySetInnerHTML={{__html: ‘Select Scenario: &nbsp;’}} /> Or: <div>&nbsp;</div> jsfiddle Update After seeing some of the comments, and trying it out. It has come to my attention that using html entites inside JSX works fine (unlike what is stated in the above jsx-gotchas reference [maybe it’s outdated]). So … Read more

Why shouldn’t JSX props use arrow functions or bind?

Why you shouldn’t use inline arrow functions in JSX props Using arrow functions or binding in JSX is a bad practice that hurts performance, because the function is recreated on each render. Whenever a function is created, the previous function is garbage collected. Rerendering many elements might create jank in animations. Using an inline arrow … Read more

React.js: Identifying different inputs with one onChange handler

I suggest sticking to standard HTML attributes like name on input Elements to identify your inputs. Also, you don’t need to keep “total” as a separate value in state because it is composable by adding other values in your state: var Hello = React.createClass({ getInitialState: function() { return {input1: 0, input2: 0}; }, render: function() … Read more