Skip to content

Instantly share code, notes, and snippets.

Voon Ming Hann eldyvoon

  • Malaysia
Block or report user

Report or block eldyvoon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View compOne.js
import useCounter from "./useCounter";
const CompOne = ({ initCounter }) => {
const [count, increase] = useCounter(initCounter);
return (
<div>
Count: {count}
<button onClick={increase}>+</button>
</div>
View useCcounter.js
import { useState } from "react";
const useCounter = initCount => {
const [count, setCount] = useState(initCount);
return [
count,
() => setCount(count => count + 1),
() => setCount(count => count - 1)
];
View CompOne.js
import Counter from "./renderPropCounter";
const CompOne = ({ initCounter }) => (
<Counter initCounter={initCounter}>
{({ count, increase }) => (
<div>
Count: {count}
<button onClick={increase}>+</button>
</div>
)}
View renderPropCounter.js
class Counter extends Component {
constructor(props) {
super(props);
this.state = { count: props.initCounter };
}
increase = () => this.setState(prevState => ({ count: prevState.count + 1 }));
decrease = () => this.setState(prevState => ({ count: prevState.count - 1 }));
render() {
View CompOne.js
import CounterHoc from "./CounterHOC";
const CompOne = ({ count, increase }) => (
<div>
Count: {count}
<button onClick={increase}>+</button>
</div>
);
export default CounterHoc(CompTwo);
View CounterHoc.js
const CounterHOC = ComposedComponent =>
class extends Component {
constructor(props) {
super(props);
this.state = {
count: props.initCounter
};
}
@eldyvoon
eldyvoon / js
Created Jun 29, 2019
Users.split.spec.js
View js
import React from "react";
import { render, waitForElement } from "@testing-library/react";
import "jest-dom/extend-expect";
import axios from "axios";
import Users, { url } from "./Users";
afterEach(() => {
axios.get.mockClear();
});
@eldyvoon
eldyvoon / js
Created Jun 29, 2019
Users.spec.js
View js
import React from "react";
import { render, waitForElement } from "@testing-library/react";
import "jest-dom/extend-expect";
import axios from "axios";
import Users, { url } from "./Users";
test("show loader when it's fetching data, then render users' name on rows", async () => {
axios.get.mockResolvedValueOnce({
data: {
results: [
@eldyvoon
eldyvoon / js
Created Jun 29, 2019
jest.config.js
View js
module.exports = {
setupFilesAfterEnv: ["@testing-library/react/cleanup-after-each"]
};
View js
export default {
get: jest.fn().mockResolvedValue({ data: {} })
};
You can’t perform that action at this time.