I am attempting to build a dApp. The problem is I do not know modern javascript, nor solidity. I am learning to react as I build the product to ensure that I can hit my overall goal of building foreveraward.com
Import curly braces
This question is asked on StackOverflow with a great answer
Specifically, if I have a statement with the following:
import { A } from './A'
This is a named import called A and only works if there is a named export called A
export const A = 42
A module can only have one default export, but as many named exports as you’d like (zero, one, two, or many). You can import them all together:
// B.js
import A, { myA, Something } from './A'
State
State has primarily been used with classes, but now with State Hooks since React 16.8 - it lets the developer use state and other react features without a class.
Basing log off of here
State also has lifecycles, and this is used in classes. There are some methods meant to be overridden for mounting and unmounting a component. These are known as lifecycle methods
componentDidMount() {
}
componentWillUnmount() {
}
There are two Class methods that will mount (load the component) and unload the component
this.state
is how state is managed in classes.
setState(updater, [callback])
setState() enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the updated state. This is the primary method you use to update the user interface in response to event handlers and server responses.
Arrow functions
- In short, with arrow functions, there are No binding of
this
- the
this
keyword always represents the object that defined the arrow function
in regular methods the this
keyword could represent the calling method, like the button in a form, this inside the method could represent that, while in an arrow function this
represents the object that creates the arrow function.
Promise
A Promise object is simply a wrapper around a value that may or may not be known when the object is instantiated and provides a method for handling the value after it is known (also known as resolved) or is unavailable for a failure reason (we’ll refer to this as rejected).