The Starter Code
The Solution Code
Explain that we will be creating seperate components today for the project. We will take the counter component and the color picker from the break out yesterday and combine them into one application. We will need to export each component and import them in to the main index.js file.
https://www.geeksforgeeks.org/reactjs-importing-exporting/
Importing default export: Every module is said to have at most one default export. In order to import the default export from a file, we can use only the address and use the keyword import before it, or we can give a name to the import making the syntax as the following.
import GIVEN_NAME from ADDRESS
Importing named values: Every module can have several named parameters and in order to import one we should use the syntax as follows.
import { PARA_NAME } from ADDRESS
And similarly for multiple such imports we can use a comma to seperate two parameter name within the curly braces.
From Stackoverflow: https://stackoverflow.com/questions/36426521/what-does-export-default-do-in-jsx
Named exports - for example export function func() {}
is a named export with the name of func
. Named modules can be imported using import { exportName } from 'module';.
In this case, the name of the import should be the same as the name of the export. To import the func in the example, you'll have to use import { func } from 'module';
. There can be multiple named exports in one module.
Default export - is the value that will be imported from the module, if you use the simple import statement import X from 'module'
. X is the name that will be given locally to the variable assigned to contain the value, and it doesn't have to be named like the origin export. There can be only one default export.
A module can contain both named exports and a default export, and they can be imported together using import defaultExport, { namedExport1, namedExport3, etc... } from 'module';
.
We will start by creating several components we will need to render our Cards.
We will be passing props from our parent component to each of our child components.
First let's set up the Child components and hard code in some data until we set up props in our parent component.
import React from "react";
function Copy(props) {
return <p>Copy</p>;
}
export default Copy;
import React from "react";
const Title = (props) => <h2 className="title">Name</h2>;
export default Title;
import React from "react";
const PridePoints = (props) => {
return (
<div className="point-container">
<button>✚</button>
<p className="points">1 Pride Level</p>
</div>
);
};
export default PridePoints;