I’m trying to test out the carousel but when I load the page it is blank. I installed react bootstrap with npm. The carousal code is from https://react-bootstrap.github.io/components.html#media-content. I looked at my web console and I don’t have any warnings or errors either. carousal.js index.js…
Tag: ecmascript-6
How does `Array.from({length: 5}, (v, i) => i)` work?
I may be missing something obvious here but could someone breakdown step by step why Array.from({length: 5}, (v, i) => i) returns [0, 1, 2, 3, 4]? https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from I didn’t understand in detail why this works Answer When Javascri…
Use reselect selector with parameters
How do I pass additional parameters to combined selectors? I am trying to • Get data • Filter data • Add custom value to my data set / group data by myValue console.log(myValue) returns undefined Answer Updated: 16 February 2022 New Solution from Reselect 4.1: See detail Updated: 6 March 2021 Solution from Re…
Serializing an ES6 class object as JSON
I’d like to serialize myClass object to json. One easy way I can think of is, since every member is actually javascript object (array, etc..) I guess I can maintain a variable to hold the member variables. this.prop.foo = this.foo and so on. I expected to find a toJSON/fromJSON library for class objects…
Custom Error Object with Apollo Server
I’m trying to use a custom error with apollo-server and it seems that my custom error has a property (code) that isn’t available from within formatError. I have a simple error handler works something like this: I’m having trouble because when I log error.code from within formatError it’…
Why do both Promise’s then & catch callbacks get called?
I have the following code and when it’s executed, it returns both “rejected” and “success”: Could anyone explain why success is logged? Answer The then callback gets called because the catch callback is before it, not after. The rejection has already been handled by catch. If you…
Re-export default in ES 6 modules
In ES6, is it possible to shorten the following code. I have an App.js file and an index.js. index.js Something like this index.js Answer If you use proposal-export-default-from Babel plugin (which is a part of stage-1 preset), you’ll be able to re-export default using the following code: For more infor…
Arrow function without curly braces
I’m new to both ES6 and React and I keep seeing arrow functions. Why is it that some arrow functions use curly braces after the fat arrow and some use parentheses? For example: vs. Answer The parenthesis are returning a single value, the curly braces are executing multiple lines of code. Your example lo…
Concatenating variables and strings in React
Is there a way to incorporate React’s curly brace notation and an href tag? Say we have the following value in the state: and the following HTML attributes on a tag: Is there a way I can add the id state to the HTML attribute to get something like this: Which will yield: Answer You’re almost corre…
hasNext() for ES6 Generator
How would I implement hasNext() method for a generator. I have tried many options like adding the generator as a return statement and yielding from the closure. Getting the first value printing it and then using the while etc, but none of them actually worked. I know I can use for of or while like How to loop…