This file contains hidden or 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 button = document.querySelector("#like-btn") | |
| button.addEventListener('click', handleClick) | |
| function handleClick(event){ | |
| console.log("Button clicked!") | |
| } |
This file contains hidden or 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
| // pass in event type, options | |
| const clickEvent = new Event("click", {"bubbles":true, "cancelable":false}); | |
| //call event on element | |
| button.dispatchEvent(clickEvent); | |
| //=> "Button clicked!" |
This file contains hidden or 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
| // This event has different options | |
| const kbEvent = new KeyboardEvent('keypress', { | |
| key:"e" | |
| shiftKey:"true" | |
| }); | |
| //see how the event is called on document | |
| document.dispatchEvent(kbEvent); |
This file contains hidden or 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 colorBtnSim = document.querySelector(".simulate-color"); | |
| const divToChange = colorBtn.parentElement; | |
| colorBtnSim.addEventListener('click', colorBtnSimClicked); | |
| function colorBtnSimClicked(event){ | |
| const colors = ["skyblue", "green", "orange", "yellow"]; | |
| event.target.parentElement.style.backgroundColor = colors[Math.floor(Math.random()*colors.length)]; | |
| } |
This file contains hidden or 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
| store.dispatch({type: 'WITHDRAW', amount: 10}) |
This file contains hidden or 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 = { | |
| balance: 0 | |
| } | |
| function rootReducer(state = initialState, action) { | |
| switch (action.type) { | |
| case 'WITHDRAW': | |
| return{...state, balance: state.balance - action.amount} | |
| case 'DEPOSIT': | |
| return {...state, balance: state.balance + action.amount} |
This file contains hidden or 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 {createStore} from 'redux' | |
| import rootReducer from './reducer.js' | |
| const store = createStore(rootReducer) |
This file contains hidden or 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 from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import './index.css'; | |
| import App from './App'; | |
| import { Provider } from 'react-redux'; | |
| import { createStore } from 'redux'; | |
| import rootReducer from './reducer' | |
| const store = createStore(rootReducer) |
This file contains hidden or 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'; | |
| class Counter extends Component{ | |
| render(){ | |
| return( | |
| <div> | |
| <button onClick={this.props.deposit}>Deposit $10</button> |
This file contains hidden or 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'; | |
| class Counter extends Component{ | |
| state={ | |
| balance: 0 | |
| } | |
| //const withdraw10 = () => {...} | |
| //const deposit10 = () => {...} | |
| render(){ |
OlderNewer