Skip to content

Instantly share code, notes, and snippets.

View I-keep-trying's full-sized avatar

Dre I-keep-trying

  • Hell
View GitHub Profile
@I-keep-trying
I-keep-trying / gist:505411640ce7a58363ff603e065879ad
Last active March 9, 2021 20:42
Works but cannot set state
import React, { useState, useEffect } from 'react'
const countriesList = [
{ name: 'Afghanistan' },
{ name: 'Åland Islands' },
{ name: 'Albania' },
{ name: 'Algeria' },
{ name: 'American Samoa' },
{ name: 'Andorra' },
{ name: 'Angola' },
import React, { useState, useEffect } from 'react'
const countriesList = [
{ name: 'Afghanistan' },
{ name: 'Åland Islands' },
{ name: 'Albania' },
{ name: 'Algeria' },
{ name: 'American Samoa' },
{ name: 'Andorra' },
{ name: 'Angola' },
@I-keep-trying
I-keep-trying / gist:36cc9750d642b8c8f75bc6bdb9422ee6
Created March 9, 2021 17:17
countries works but no api request
import React, { useState, useEffect } from 'react'
const countriesList = [
{ name: 'Afghanistan' },
{ name: 'Åland Islands' },
{ name: 'Albania' },
{ name: 'Algeria' },
{ name: 'American Samoa' },
{ name: 'Andorra' },
{ name: 'Angola' },
import React, { useState, useEffect } from 'react'
const countriesList = [
{ name: 'Afghanistan' },
{ name: 'Åland Islands' },
{ name: 'Albania' },
{ name: 'Algeria' },
{ name: 'American Samoa' },
{ name: 'Andorra' },
{ name: 'Angola' },
@I-keep-trying
I-keep-trying / gist:7e9111c620dc968ba8f122f0852255fe
Created December 10, 2020 22:02
String replace/filter/whatever
import { object } from 'prop-types'
import React, { useState } from 'react'
const stringArray = [
{ word: 'bassoon', score: 371 },
{ word: 'barroon', score: 371 },
{ word: 'babboon', score: 371 },
]
const App = () => {
@I-keep-trying
I-keep-trying / part6a.md
Last active August 26, 2020 21:05
part 6a suggestions
mainImage part letter lang
../../../images/part-6.svg
6
a
en

So far, we have followed the state management conventions recommended by React. We have placed the state and the methods for handling it to the root component of the application. The state and its handler methods have then been passed to other components with props. This works up to a certain point, but when applications grow larger, state management becomes challenging.

import React from 'react'
import { useDispatch } from 'react-redux'
const App = () => {
const dispatch = useDispatch()
//works as expected
const good = () => {
dispatch({
type: 'GOOD',
@I-keep-trying
I-keep-trying / index.js
Created June 15, 2020 19:55
redux counter app
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import { useDispatch } from 'react-redux'
import './index.css'
const counterReducer = (state = 0, action) => {
switch (action.type) {
import deepFreeze from 'deep-freeze'
import { createStore } from 'redux'
describe('counter', () => {
it('increment', () => {
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
import React, { useState } from 'react'
const PersonForm = props => {
console.log('props', props)
return (
<form onSubmit={props.handleSubmit}>
<div>
Name:
<input
name="name"