An online markdown blog and knowledge repository.
Wednesday 13-Apr-2022
Reviewed a simple Python file and it went well.
I chose the for loop after failing to get for...in to work properly.
Sheyna chose for...in to solve this.
The key takeaway seems to be pushing return value to a new array to get something back out.
Use npm -i ?? when downloading React repo from a foreign source
To pull-in data from a json file named data.json: import data from './data.json';
Use lowercase to assign data import file data.
Use PascalCase for the Components.
Files that are '.js' extensions in the Imports section do not need to specify their extension.
File extensions other than '.js' must be specified.
Component imports can just be their Capitalized name, without specifying '.js'.
Special function this.setState()
allows changing data within that component instance.
A Component's constructor is constantly listening for state changes, so using 'setState' in the constructor causes an infinite loop, and should be avoided.
Use import bootstrap/dist/css/bootstrap.min.css;
to add baseline styling.
Also import Card and ListGroup if using those.
Import <row>
and <col>
by using import Row from react-boostrap/Row;
Add a <Col>
to the Main.render code block and include a key attribute.
Import Container using import {Container} from react-boostrap/Container;
Apply a <Container>
to surround the Component to render.
Apply a child <Row>
with some attributes (in Bootstrap-React) to set the grid.
Each individual card is wrapped within a <Col>
.
Issues with card height inconsistencies:
Multiple Imports can be done but it causes all of Bootstrap to download before extracting the ones you've selected within braces.
Resource: HackerThemes
Install multiple libraries at a time: npm install component1 component2... ...
Code Challenge: Class 03
"Filter"
An array method.
Create a new array with all elements that 'pass a test' implemented by the provided function.
Will return an empty array if nothing matches the filter argument.
"People of 301 Project" as a demo.
Lab goals:
Child Component has a click event that needs to change data in another Component, possibly in a completely different branch of the React DOM tree.
Only a the Component itself can change its own state.
Add value and state infomation to the common ancestor Component.
Add a handler in the common ancestor Component.
When common ancestor render function fires, it needs to send info down the React data flow.
In the common Parent:
this.state = { propertyName: value, };
evtHandler = () => { this.setState({ propertyName: this.state.propertyName + ' '}) } // string concatenation
In the child with the event:
this.props
.onClick={this.props.addHearts}
.They inherit the context of where they are declared.
Modals are dialogs for notifications and user-directed messages.
Self-contained within the Window in which they are launched.
Code401 teaches this, but in Code301 we will continue using Class Components.
So don't just copy-and-paste from resources without looking at how it works.
Add a property to App.js to boolean show/hide a Modal.
Import Modal from Bootstrap import Modal from 'react-bootstrap/Modal';
Add a Modal component inside the App.render's return codeblock.
Supply attributes show={this.state.showProperty}
and onHide={this.hideModelHandler}
.
'show' and 'onHide' attributes are built-in to the Modal Component.
There are buttons, footers, bodies, and other properties that can be set on a Modal.
Moving the data.js file into App.js forces you to:
Before deploying a React app: