This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//lets make a function the returns Hello would | |
const add = (a, b) => { | |
if(a && b){ | |
return a + b | |
} | |
return 'No Numbers' | |
} | |
const subtract = (a, b) => { | |
if(a, b){ | |
return a - b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//lets make a function the returns Hello would | |
const add = (a, b) => { | |
if(a && b){ | |
return a + b | |
} | |
return 'No Numbers' | |
} | |
const subtract = (a, b) => { | |
if(a, b){ | |
return a - b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//if we declare a variable | |
const myString = "My sting says Hello"// Here we are telling the browser "allocate memory for a string" | |
const num = 1000 //again were telling the heap to allocate memory for this variable that is an integer | |
// lets switch things up a bit, if i open an object literal like so: | |
const Cameron = { | |
firstName: 'cameron', | |
lastName: 'Leverett', | |
} | |
// This mean I want to allocate memory for an object and have it point the the follwoing keys wich point the the following values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//JavaScript syntax | |
const myObject = { | |
address: '126.001.01.1'//not a real address just random digits | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check to see if one array is in another array. | |
const arrOne = ["a", "b", "c", "d", "e"] | |
const arrTwo = [1, "b", 2, 3, 4] | |
//we want to return true if any elments from array one exist inside array two. | |
//let define a funtion that can solve this problem | |
const compare = (arr1, arr2) => { | |
let hashMap = {}// set an empty object | |
for(let i = 0; i < arr1.length; i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// it must be written exactly like this. | |
export async function getStaticProps(context){...0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// it must be written exactly like this. | |
export async function getStaticProps(context){...0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HomePage = (props) => { | |
return ( | |
<div> | |
<li></li> | |
<li></li> | |
<li></li> | |
</div> | |
) | |
} | |
// we always want to return an object with a key props |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//as long as we don't attempt to use this in the client side code Next will split this away from the client side render. so the client wont see this import. | |
import fs from 'fs' | |
... | |
export const getStaticProps = async() => { | |
//normally we would not be able to run the fs.readFile() method but with Next we can actually import this in here and use the same way we would in a node application. | |
fs.readFileSync() | |
return {props: { | |
products: [id: 'p1', title: 'Product 1'] | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//we can actually import what ever node modules we want as long as we only use them in the getStaticProps method | |
import path from 'path'; | |
... | |
export const getStaticProps = async() => { | |
//proccess is a global object that can be accessed anywhere with in a node application. Because nextJS doesn't read getStaticProps as a client file we can use the process object. | |
//cwd = current working directory. and will actually view the current directory as the top level. | |
const filePath = path.join(process.cwd()) | |
return {props: { | |
products: [id: 'p1', title: 'Product 1'] |
OlderNewer