- Q: Makes sense to move useEffects to hooks which you have to load data? > A: I believe so. Every time I access a duck which loads external data, I'm interested in its data, not in calling a funciton to load it.
๐ฆ
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 { useLoadingMocked } from 'assets/__mocks__/useLoading'; | |
| // mock module as a function | |
| jest.mock('src/redux/loading', () => jest.fn()); | |
| import methodToMock from 'src/redux/loading'; | |
| const mockedMethod = methodToMock as jest.Mock; | |
| describe('testing a hook', () => { | |
| it('my test', () => { |
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 Comp = (props) => { | |
| const myRef = useRef() | |
| const [activeState, setActiveState] = useState(false) | |
| const callbackTrue = () => { | |
| // define callback | |
| setActiveState(true) | |
| } | |
| const callbackFalse = () => { |
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 concatComponents = (...listComponents) => listComponents | |
| const MyComp = (props) => { | |
| const myConcatenatedText = concatComponents( | |
| 'My text with ', | |
| <a>My link</a>, | |
| 'end of my text with', | |
| ) | |
| 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
| react | |
| ink | |
| ink-text-input | |
| typescript | |
| @types/react | |
| @types/node |
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
| state = [ | |
| action1, | |
| action1, | |
| ] | |
| // hook | |
| const useFilterPedingAction = key => state.filter(item => ( | |
| item.status === 'pending' && | |
| item.name === key | |
| )) |
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
| # set npm env | |
| export NPM_HOME=$HOME/.npm-global | |
| npm config set prefix $NPM_HOME | |
| # set node bin to path | |
| export PATH=$PATH:$NPM_HOME/bin |
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
| /* | |
| Enter your query here. | |
| Please append a semicolon ";" at the end of the query | |
| */ | |
| SELECT c.name, MAX(p.id) | |
| FROM customer as c, payment as p | |
| WHERE p.status LIKE "CO" and p.customer_id = c.id | |
| GROUP BY c.name | |
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
| /* | |
| Enter your query here. | |
| Please append a semicolon ";" at the end of the query | |
| */ | |
| SELECT c.name, MAX(p.id) | |
| FROM customer as c, payment as p | |
| WHERE p.status LIKE "CO" and p.customer_id = c.id | |
| GROUP BY c.name | |