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
import React, { Component } from 'react'; | |
import { Switch, Route } from 'react-router-dom'; | |
import {connect} from 'react-redux'; | |
import {getProfileFetch, logoutUser} from './redux/actions'; | |
import Signup from './components/Signup'; | |
import Login from './components/Login'; | |
class App extends Component { | |
componentDidMount = () => { |
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
export const getProfileFetch = () => { | |
return dispatch => { | |
const token = localStorage.token; | |
if (token) { | |
return fetch("http://localhost:3000/api/v1/profile", { | |
method: "GET", | |
headers: { | |
'Content-Type': 'application/json', | |
Accept: 'application/json', | |
'Authorization': `Bearer ${token}` |
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
import React, { Component } from 'react'; | |
import { Switch, Route } from 'react-router-dom'; | |
import {connect} from 'react-redux'; | |
import {getProfileFetch} from './redux/actions'; | |
import Signup from './components/Signup'; | |
import Login from './components/Login'; | |
class App extends Component { |
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
export const userLoginFetch = user => { | |
return dispatch => { | |
return fetch("http://localhost:3000/api/v1/login", { | |
method: "POST", | |
headers: { | |
'Content-Type': 'application/json', | |
Accept: 'application/json', | |
}, | |
body: JSON.stringify({user}) | |
}) |
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
import React, {Component} from 'react'; | |
import {connect} from 'react-redux'; | |
import {userLoginFetch} from '../redux/actions'; | |
class Login extends Component { | |
state = { | |
username: "", | |
password: "" | |
} |
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 initialState = { | |
currentUser: {} | |
} | |
export default function reducer(state = initialState, action) { | |
switch (action.type) { | |
case 'LOGIN_USER': | |
return {...state, currentUser: action.payload} | |
default: | |
return state; |
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
export const userPostFetch = user => { | |
return dispatch => { | |
return fetch("http://localhost:3000/api/v1/users", { | |
method: "POST", | |
headers: { | |
'Content-Type': 'application/json', | |
Accept: 'application/json', | |
}, | |
body: JSON.stringify({user}) | |
}) |
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
import React, {Component} from 'react'; | |
import {connect} from 'react-redux'; | |
import {userPostFetch} from '../redux/actions'; | |
class Signup extends Component { | |
state = { | |
username: "", | |
password: "", | |
avatar: "", | |
bio: "" |
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
// 🐢 custom hook - name starts with "use" (useMedium) | |
useMedium(() => { | |
const URI = "https://some-path-api"; | |
// 🦄 custom hook can use any of the default | |
// React hooks - this is NOT compulsory. | |
useEffect(() => { | |
fetch(URI) | |
},[]) | |
}) |
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
function CounterHooks() { | |
const [count, setCount] = useState(0); | |
const [time, setTime] = useState(new Date()) | |
// 🐢 look here. | |
useEffect(() => { | |
console.log("useEffect first timer here.") | |
}, [count]) | |