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 users = [ | |
| { name: "John", age: 24 }, | |
| { name: "Linda", age: 19 }, | |
| { name: "Josh", age: 33 } | |
| ]; | |
| function App() { | |
| const renderUsers = () => { | |
| const result = []; | |
| for (let i = 0; i < users.length; i++) { |
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 { Link } from "react-router-dom"; | |
| import { HashScroll } from "react-hash-scroll"; | |
| const HashScrollPage = () => { | |
| return ( | |
| <main className="page"> | |
| <nav> | |
| <ul> | |
| <li> |
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 { | |
| Link, | |
| Element, | |
| Events, | |
| animateScroll as scroll, | |
| scroller, | |
| } from "react-scroll"; | |
| import "./ReactScroll.css"; |
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"; | |
| const App = () => { | |
| return ( | |
| <div className="container"> | |
| <button | |
| onClick={() => | |
| window.scrollTo({ | |
| left: 0, | |
| top: window.innerHeight, |
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"; | |
| const App = () => { | |
| return ( | |
| <div className="container"> | |
| <button onClick={() => window.scrollTo(0, window.innerHeight)}> | |
| Scroll to bottom | |
| </button> | |
| <button onClick={() => window.scrollTo(0, 0)}>Scroll top top</button> | |
| </div> |
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, { createRef } from 'react'; | |
| class App extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.scollToRef = createRef(); | |
| } | |
| render() { | |
| return ( |
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, { useRef } from 'react'; | |
| const App = () => { | |
| const scollToRef = useRef(); | |
| return ( | |
| <div className="container"> | |
| <button onClick={() => scollToRef.current.scrollIntoView()}> | |
| Scroll | |
| </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 from "react"; | |
| import { connect } from "react-redux"; | |
| const Users = ({ users }) => { | |
| return ( | |
| <ul> | |
| {users.map((user) => ( | |
| <li key={user.id}>{user.name}</li> | |
| ))} | |
| </ul> |
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 { Provider } from "react-redux"; | |
| import userReducer from "./reducers/userReducer"; | |
| // Creating instance of a store | |
| const store = createStore({ | |
| users: userReducer, | |
| }); | |
| const App = () => { |
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 = []; | |
| const usersReducer = (state = initialState, action) => { | |
| switch (action.type) { | |
| case "SET_USERS": | |
| return action.payload; | |
| case "ADD_USER": | |
| return [...state, action.payload]; | |
| case `EDIT_USER`: | |
| const newState = [...state]; |