Skip to content

Instantly share code, notes, and snippets.

View viknedus's full-sized avatar
:octocat:
Hey

Victor Nwachukwu viknedus

:octocat:
Hey
View GitHub Profile
@viknedus
viknedus / With-Async.js
Created August 30, 2021 09:42
Two pieces of JS code with and without Async, Await
export const getSingleTaskAction = id => {
return async dispatch => {
dispatch({ type: types.TASKS_START });
try {
const res = await codeClanApi
.get(`/tasks/${id}`);
dispatch({ type: types.GET_TASK, payload: res.data });
} catch (err) {
const error_msg = err.response
? err.response.data.message
@viknedus
viknedus / randomHexColor.js
Created August 9, 2021 09:59
Randomize Hex color for React
const randomHexColor = () => {
return '#000000'.replace(/0/g, () => {
return (~~(Math.random() * 16)).toString(16);
});
};
// CSS
* {backgroundColor: randomHexColor(),}