Skip to content

Instantly share code, notes, and snippets.

View codewithbernard's full-sized avatar

Bernard Bado codewithbernard

View GitHub Profile
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++) {
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>
import React, { Component } from "react";
import {
Link,
Element,
Events,
animateScroll as scroll,
scroller,
} from "react-scroll";
import "./ReactScroll.css";
import React from "react";
const App = () => {
return (
<div className="container">
<button
onClick={() =>
window.scrollTo({
left: 0,
top: window.innerHeight,
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>
import React, { createRef } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.scollToRef = createRef();
}
render() {
return (
import React, { useRef } from 'react';
const App = () => {
const scollToRef = useRef();
return (
<div className="container">
<button onClick={() => scollToRef.current.scrollIntoView()}>
Scroll
</button>
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>
import { Provider } from "react-redux";
import userReducer from "./reducers/userReducer";
// Creating instance of a store
const store = createStore({
users: userReducer,
});
const App = () => {
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];