-
Notifications
You must be signed in to change notification settings - Fork 1
/
React.js
1549 lines (1064 loc) · 36.3 KB
/
React.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -------------------------------------------------- */
Basics
/* -------------------------------------------------- */
JSX
Allows us to write HTML like syntax which gets transformed to lightweight JavaScript objects.
Virtual DOM
A JavaScript representation of the actual DOM.
React.createClass
The way in which you create a new component.
render (method)
What we would like our HTML Template to look like.
ReactDOM.render
Renders a React component to a DOM node.
state
The internal data store (object) of a component.
getInitialState
The way in which you set the initial state of a component.
setState
A helper method for altering the state of a component.
props
The data which is passed to the child component from the parent component.
propTypes
Allows you to control the presence, or types of certain props passed to the child component.
getDefaultProps
Allows you to set default props for your component.
Component LifeCycle
componentWillMount
Fired before the component will mount
componentDidMount
Fired after the component mounted
componentWillReceiveProps
Fired whenever there is a change to props
componentWillUnmount
Fired before the component will unmount
Events
onClick
onSubmit
onChange
/* -------------------------------------------------- */
Quickstart
/* -------------------------------------------------- */
Creating a Single Page Application
Create React App is the best way to start building a new React single page application. It sets up your development environment so that you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production.
Console
npm install -g create-react-app
create-react-app hello-world
cd hello-world
npm start
Create React App doesnt handle backend logic or databases; it just creates a frontend build pipeline, so you can use it with any backend you want. It uses webpack, Babel and ESLint under the hood, but configures them for you.
/* -------------------------------------------------- */
GitHub Pages
/* -------------------------------------------------- */
create-react-app
Comes with detailed documentation to help users publish their work using all sorts of tools.
Steps
Edit - package.json
"homepage": "https://<github-username>.github.io/<project-repo>"
"https://danlin604.github.io/react/"
Run - npm run build
reate-react-app CLI github tooltip displayed
Install - npm install --save-dev gh-pages
gh-pages is a special branch that GitHub Pages uses to publish projects.
Edit - package.json - "scripts"
"deploy" : "npm run build&&gh-pages -d build"
Run - npm run deploy
Verify - GitHub - project repo
Settings --> GitHub Pages --> Source --> gh-pages branch
Published @ "https://danlin604.github.io/react/"
/* -------------------------------------------------- */
CSS
/* -------------------------------------------------- */
Old School
.main .sidebar .button
Complicated on larger applications
CSS Methodologies
once you adopt one, you are pretty much stuck with that and its going to be difficult to migrate.
OOCSS (Object Oriented CSS)
SMACSS (Scalable and Modular Approach for CSS)
BEM (Block Element Modifier)
BEM originates from Yandex. The goal of BEM is to allow reusable components and code sharing.
React Inline
CSS is powerful, but it can become an unmaintainable mess without some discipline. Where do we draw the line between CSS and JavaScript?
styling at the component level
/* Instead of
render(props, context) {
const notes = this.props.notes;
return <ul className='notes'>{notes.map(this.renderNote)}</ul>;
}
*/
/* Use
render(props, context) {
const notes = this.props.notes;
const style = {
margin: '0.5em',
paddingLeft: 0,
listStyle: 'none'
};
return <ul style={style}>{notes.map(this.renderNote)}</ul>;
}
*/
It is going to be difficult to perform large, sweeping changes to our codebase as we need to tweak a lot of components to achieve that.
/* -------------------------------------------------- */
Code Academy React Course
/* -------------------------------------------------- */
React is fast. Apps made in React can handle complex updates and still feel quick and responsive.
React is modular. Instead of writing large, dense files of code, you can write many smaller, reusable files. React's modularity can be a beautiful solution to JavaScript's maintainability problems.
React is scalable. Large programs that display a lot of changing data are where React performs best.
React is flexible. You can use React for interesting projects that have nothing to do with making a web app. People are still figuring out React's potential. There's room to explore.
React is popular. While this reason has admittedly little to do with React's quality, the truth is that understanding React will make you more employable.
/* -------------------------------------------------- */
JSX
/* -------------------------------------------------- */
// Example
const h1 = <h1>Hello world</h1>;
JSX is a syntax extension for JavaScript. It was written to be used with React. JSX code looks a lot like HTML.
What does "syntax extension" mean?
In this case, it means that JSX is not valid JavaScript. Web browsers can't read it!
If a JavaScript file contains JSX code, then that file will have to be compiled. That means that before the file reaches a web browser, a JSX compiler will translate any JSX into regular JavaScript.
// JSX Element
A basic unit of JSX is called a JSX element.
// Example JSX Element
<h1>Hello world</h1>
JSX elements are treated as JavaScript expressions. They can go anywhere that JavaScript expressions can go.
That means that a JSX element can be saved in a variable, passed to a function, stored in an object or array...you name it.
// JSX Element saved as variable
const navBar = <nav>I am a nav bar</nav>;
const myTeam = {
center: <li>Benzo Walli</li>,
powerForward: <li>Rasha Loa</li>,
smallForward: <li>Tayshaun Dasmoto</li>,
shootingGuard: <li>Colmar Cumberbatch</li>,
pointGuard: <li>Femi Billon</li>
};
// Attributes in JSX
JSX elements can have attributes, just like HTML elements can.
const title = <h1 id="title">Introduction to React.js: Part I</h1>;
const panda = <img src="images/panda.jpg" alt="panda" width="500px" height="500px" />;
// Nested JSX
You can nest JSX elements inside of other JSX elements, just like in HTML.
<a href="https://www.example.com"><h1>Click me!</h1></a>
// Multiline JSX
(
<a href="https://www.example.com">
<h1>
Click me!
</h1>
</a>
)
// Save nested JSX expression
const theExample = (
<a href="https://www.example.com">
<h1>
Click me!
</h1>
</a>
);
// JSX Outer Elements
JSX expression must have exactly one outermost element.
// Working
const paragraphs = (
<div id="i-am-the-outermost-element">
<p>I am a paragraph.</p>
<p>I, too, am a paragraph.</p>
</div>
);
// Broken
const paragraphs = (
<p>I am a paragraph.</p>
<p>I, too, am a paragraph.</p>
);
// Rendering JSX in app.js
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(<h1>Hello world</h1>, document.getElementById('app'));
// ReactDOM
ReactDOM is the name of a JavaScript library. This library contains several React-specific methods, all of which deal with the DOM in some way or another.
// Example
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Render me!</h1>,
document.getElementById('app')
);
/* index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/styles.css">
<title>Learn ReactJS</title>
</head>
<body>
<main id="app"></main>
</body>
</html>
*/
// Passing a variable to ReactDOM.render()
const toDoList = (
<ol>
<li>Learn React</li>
<li>Become a Developer</li>
</ol>
);
ReactDOM.render(
toDoList,
document.getElementById('app')
);
// Virtual DOM
One special thing about ReactDOM.render() is that it only updates DOM elements that have changed.
This is significant! Only updating the necessary DOM elements is a large part of what makes React so successful.
React accomplishes this thanks to something called the virtual DOM.
In React, for every DOM object, there is a corresponding "virtual DOM object." A virtual DOM object is a representation of a DOM object, like a lightweight copy.
A virtual DOM object has the same properties as a real DOM object, but it lacks the real thing's power to directly change what's on the screen.
Manipulating the DOM is slow. Manipulating the virtual DOM is much faster, because nothing gets drawn onscreen. Think of manipulating the virtual DOM as editing a blueprint, as opposed to moving rooms in an actual house.
// class vs className
// HTML
<h1 class="big">Hey</h1>
// JSX
<h1 className="big">Hey</h1>
// When JSX is rendered, JSX className attributes are automatically rendered as class attributes.
// Self-closing tags
/*
Fine in HTML with a slash:
<br />
Also fine, without the slash:
<br>
Fine in JSX:
<br />
NOT FINE AT ALL in JSX:
<br>
*/
// JavaScript in JSX
ReactDOM.render(
<h1>2 + 3</h1>, // 2 + 3
document.getElementById('app')
);
// Any code in between the tags of a JSX element will be read as JSX, not as regular JavaScript! JSX doesn't add numbers - it reads them as text, just like HTML.
// You need curley braces!
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>{2 + 3}</h1>,
document.getElementById('app')
);
// More example
const math = <h1>2 + 3 = {2 + 3}</h1>;
ReactDOM.render(
math,
document.getElementById('app')
);
// Variables in JSX
const theBestString = 'tralalalala i am da best';
ReactDOM.render(<h1>{ theBestString }</h1>, document.getElementById('app'));
// Variable Attributes in JSX
const sideLength = "200px";
const panda = (
<img
src="images/panda.jpg"
alt="panda"
height={sideLength}
width={sideLength} />
);
// More examples
const pics = {
panda: "http://bit.ly/1Tqltv5",
owl: "http://bit.ly/1XGtkM3",
owlCat: "http://bit.ly/1Upbczi"
};
const panda = (
<img
src={pics.panda}
alt="Lazy Panda" />
);
const owl = (
<img
src={pics.owl}
alt="Unimpressed Owl" />
);
const owlCat = (
<img
src={pics.owlCat}
alt="Ghastly Abomination" />
);
// Event Listeners in JSX
function myFunc() {
alert('Hello');
}
<img onClick={myFunc} />
// Note that in HTML, event listener names are written in all lowercase, such as onclick or onmouseover. In JSX, event listener names are written in camelCase, such as onClick or onMouseOver
// JSX Conditionals: If Statements That Don't Work
// This code will break
(
<h1>
{
if (purchase.complete) {
'Thank you for placing an order!'
}
}
</h1>
)
// JSX Conditionals: If Statements That Do Work
import React from 'react';
import ReactDOM from 'react-dom';
let message;
if (user.age >= drinkingAge) {
message = (
<h1>
Hey, check out this alcoholic beverage!
</h1>
);
} else {
message = (
<h1>
Hey, check out these earrings I got at Claire's!
</h1>
);
}
ReactDOM.render(
message,
document.getElementById('app')
);
/*
if.js works, because the words if and else are not injected in between JSX tags. The if statement is on the outside, and no JavaScript injection is necessary.
This is a common way to express conditionals in JSX.
*/
// Example: coin toss
import React from 'react';
import ReactDOM from 'react-dom';
function coinToss() {
// This function will randomly return either 'heads' or 'tails'.
return Math.random() < 0.5 ? 'heads' : 'tails';
}
const pics = {
kitty: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-kitty.jpg',
doggy: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-puppy.jpeg'
};
let img;
// if/else statement begins here:
if (coinToss() === 'heads') {
img = <img src={pics.kitty} />;
} else {
img = <img src={pics.doggy} />;
}
ReactDOM.render(
img,
document.getElementById('app')
);
// JSX Conditionals: The Ternary Operator
const headline = (
<h1>
{ age >= drinkingAge ? 'Buy Drink' : 'Do Teen Stuff' }
</h1>
);
// Example
import React from 'react';
import ReactDOM from 'react-dom';
function coinToss () {
// Randomly return either 'heads' or 'tails'.
return Math.random() < 0.5 ? 'heads' : 'tails';
}
const pics = {
kitty: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-kitty.jpg',
doggy: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-puppy.jpeg'
};
const img = <img src={pics[coinToss() === 'heads' ? 'kitty' : 'doggy']} />;
ReactDOM.render(
img,
document.getElementById('app')
);
// JSX Conditionals: &&
const tasty = (
<ul>
<li>Applesauce</li>
{ !baby && <li>Pizza</li> }
{ age > 15 && <li>Brussels Sprouts</li> }
{ age > 20 && <li>Oysters</li> }
{ age > 25 && <li>Grappa</li> }
</ul>
);
// .map in JSX
const strings = ['Home', 'Shop', 'About Me'];
const listItems = strings.map(string => <li>{string}</li>);
<ul>{listItems}</ul>
// More example
import React from 'react';
import ReactDOM from 'react-dom';
const people = ['Rowe', 'Prevost', 'Gare'];
const peopleLis = people.map(person =>
// expression goes here:
<li>{ person }</li>
);
// ReactDOM.render goes here:
ReactDOM.render(
<ul>{ peopleLis }</ul>,
document.getElementById('app')
);
// Keys
<ul>
<li key="li-01">Example1</li>
<li key="li-02">Example2</li>
<li key="li-03">Example3</li>
</ul>
// A key is a JSX attribute. The attribute's name is key. The attribute's value should be something unique, similar to an id attribute.
// keys don't do anything that you can see! React uses them internally to keep track of lists. If you don't use keys when you're supposed to, React might accidentally scramble your list-items into the wrong order.
/*
Not all lists need to have keys. A list needs keys if either of the following are true:
The list-items have memory from one render to the next. For instance, when a to-do list renders, each item must "remember" whether it was checked off. The items shouldn't get amnesia when they render.
A list's order might be shuffled. For instance, a list of search results might be shuffled from one render to the next.
*/
import React from 'react';
import ReactDOM from 'react-dom';
const people = ['Rowe', 'Prevost', 'Gare'];
const peopleLis = people.map((person, i) =>
// expression goes here:
<li key={'person_' + i}>{ person }</li>
);
// ReactDOM.render goes here:
ReactDOM.render(
<ul>{ peopleLis }</ul>,
document.getElementById('app')
);
// React.createElement
You can write React code without using JSX at all!
// JSX
const h1 = <h1>Hello world</h1>;
// JS
const h1 = React.createElement(
"h1",
null,
"Hello, world"
);
/* -------------------------------------------------- */
Component
/* -------------------------------------------------- */
A component is a small, reusable chunk of code that is responsible for one job. That job is often to render some HTML.
// Example
import React from 'react';
import ReactDOM from 'react-dom';
class MyComponentClass extends React.Component {
render() {
return <h1>Hello world</h1>;
}
};
ReactDOM.render(
<MyComponentClass />,
document.getElementById('app')
);
// Import React
import React from 'react';
// This imported object contains methods that you need in order to use React. The object is called the React library.
// The methods imported from 'react' don't deal with the DOM at all. They don't engage directly with anything that isn't part of React.
// To clarify: the DOM is used in React applications, but it isn't part of React. After all, the DOM is also used in countless non-React applications. Methods imported from 'react' are only for pure React purposes, such as creating components or writing JSX elements.
// Import ReactDOM
import ReactDOM from 'react-dom';
// The methods imported from 'react-dom' are meant for interacting with the DOM. You are already familiar with one of them: ReactDOM.render().
// Create a Component Class
// Every component must come from a component class.
// A component class is like a factory that creates components. If you have a component class, then you can use that class to produce as many components as you want.
// To make a component class, you use a base class from the React library: React.Component.
// React.Component is a JavaScript class. To create your own component class, you must subclass React.Component. You can do this by using the syntax
class ComponentName extends React.Component {}
// Render Function
// There is only one property that you have to include in your instructions: a render method.
// A render method is a property whose name is render, and whose value is a function. The term "render method" can refer to the entire property, or to just the function part.
class ComponentFactory extends React.Component {
render() {
return <h1>Hello world</h1>;
}
}
// A render method must contain a return statement. Usually, this return statement returns a JSX expression.
// Create a Component Instance
// To make a React component, you write a JSX element. Instead of naming your JSX element something like h1 or div like you've done before, give it the same name as a component class.
import React from 'react';
import ReactDOM from 'react-dom';
class MyComponentClass extends React.Component {
render() {
return <h1>Hello world</h1>;
}
}
ReactDOM.render(
<MyComponentClass />, // Component Instance
document.getElementById('app')
);
/* -------------------------------------------------- */
Basics
/* -------------------------------------------------- */
// Stateless functions
const Greeting = () => <div>Hi there!</div>
// Passing props and context
const Greeting = (props, context) =>
<div style={{color: context.color}}>Hi {props.name}!</div>
// defaultProps, propTypes and contextTypes
Greeting.propTypes = {
name: PropTypes.string.isRequired
}
Greeting.defaultProps = {
name: "Guest"
}
Greeting.contextTypes = {
color: PropTypes.string
}
// props written as attributes
<main className="main" role="main">{children}</main>
// props "spread" from object
<main {...{className: "main", role: "main", children}} />
// forward props
const FancyDiv = props =>
<div className="fancy" {...props} />
<FancyDiv data-id="my-fancy-div">So Fancy</FancyDiv>
// output: <div className="fancy" data-id="my-fancy-div">So Fancy</div>
// destructure props
const Greeting = props => <div>Hi {props.name}!</div>
const Greeting = ({ name }) => <div>Hi {name}!</div>
const Greeting = ({ name, ...props }) => // rest
<div {...props}>Hi {name}!</div> // spread
// conditionals
// id
{condition && <span>Rendered when `truthy`</span> }
// unless
{condition || <span>Rendered when `falsey`</span> }
// ternary
{condition
? <span>Rendered when `truthy`</span>
: <span>Rendered when `falsey`</span>
}
// children types
//string
<div>
Hello World!
</div>
// array
<div>
{["Hello ", <span>World</span>, "!"]}
</div>
// function
<div>
{(() => { return "hello world!"})()}
</div>
// map with destructure
<ul>
{arrayOfMessageObjects.map(({ id, ...message }) =>
<Message key={id} {...message} />
)}
</ul>
// render callback with children
const Width = ({ children }) => children(500)
<Width>
{width => <div>window is {width}</div>}
</Width>
<div>window is 500</div> // output
// reusable
const MinWidth = ({ width: minWidth, children }) =>
<Width>
{width =>
width > minWidth
? children
: null
}
</Width>
// proxy component
<button type="button" /> // no proxy
// is proxy
const Button = props =></button>
<button type="button" {...props} />
// usage
<Button a='a' b='b' />
// style component
import classnames from 'classnames'
const PrimaryBtn = props =>
<Btn {...props} primary />
const Btn = ({ className, primary, ...props }) =>
<button
type="button"
className={classnames(
"btn",
primary && "btn-primary",
className
)}
{...props}
/>
// same output
<PrimaryBtn />
<Btn primary />
<button type="button" className="btn btn-primary" />
// event switch
// no switch
handleClick() { require("./actions/doStuff")(/* action stuff */) }
handleMouseEnter() { this.setState({ hovered: true }) }
// switch
handleEvent({type}) {
switch(type) {
case "click":
return require("./actions/doStuff")(/* action dates */)
case "mouseenter":
return this.setState({ hovered: true })
default:
return console.warn(`No case for event type "${type}"`)
}
}
// layout component
<HorizontalSplit
leftSide={<SomeSmartComponent />}
rightSide={<AnotherSmartComponent />}
/>
class HorizontalSplit extends React.Component {
shouldComponentUpdate() {
return false // optimized
}
render() {
<FlexContainer>
<div>{this.props.leftSide}</div>
<div>{this.props.rightSide}</div>
</FlexContainer>
}
}
// container component
// A container does data fetching and then renders its corresponding sub-component.
const CommentList = ({ comments }) =>
<ul>
{comments.map(comment =>
<li>{comment.body}-{comment.author}</li>
)}
</ul>
class CommentListContainer extends React.Component {
constructor() {
super()
this.state = { comments: [] }
}
componentDidMount() {
$.ajax({
url: "/my-comments.json",
dataType: 'json',
success: comments =>
this.setState({comments: comments});
})
}
render() {
return <CommentList comments={this.state.comments} />
}
}
// higher-order component (HOC)
const Greeting = ({ name }) => {
if (!name) { return <div>Connecting...</div> }
return <div>Hi {name}!</div>
}
const Connect = ComposedComponent =>
class extends React.Component {
constructor() {
super()
this.state = { name: "" }
}