Skip to content

Instantly share code, notes, and snippets.

View louicoder's full-sized avatar
🏠
Working remotely

Musanje Louis Michael louicoder

🏠
Working remotely
View GitHub Profile
@louicoder
louicoder / groupArray.js
Created December 14, 2022 09:33
Group array of objects into object
const grouped = array.reduce((obj, item) => {
const key = item.age;
if (!obj[key]) {
obj[key] = [];
}
obj[key].push(item);
return obj;
@louicoder
louicoder / fullWidthAndHeightImage.js
Last active July 28, 2022 11:38
Create Full Width image and Auto Height in React Native
// Get screen dimensions
const { WIDTH, HEIGHT } = Dimensions.get();
// style={{ aspectRatio: image.width / image.height }}
const getImageStyles = (imageWidth, imageHeight) => {
// WIDTH - Screen Width.
// HEIGHT - Screen Height.
return { width: WIDTH, height: imageHeight / imageWidth * WIDTH };
};
@louicoder
louicoder / HOC.js
Created May 25, 2022 07:14
Conditionally rendering the Header and Footer components in react-Router v6
// HOC component
import {Header, Footer} from '/path/to/Components';
export default ({header , footer, component: Component}) => {
return (
<div>
{header ? <Header /> : null} // check for true or false prop for rendering header
<Component /> // render component passed.
{footer ? <Footer /> : null} // check for true or false prop for rendering footer
</div>
@louicoder
louicoder / index.js
Last active April 28, 2022 07:53
moment Helper Functions
/**
* @param startDate {String} format 'YYYY-MM-DD'
* @param endDate {String} format 'YYYY-MM-DD'
* @returns Array [] String
*
*/
const enumerateDaysBetweenDates = function (startDate, endDate) {
// Start Date format should be YYYY-MM-DD
// End Date format should be YYYY-MM-DD
@louicoder
louicoder / gist:9e51392276ab8a10e794e10826f18a1f
Last active July 31, 2024 12:10
Get Keyboard Height Hook
We couldn’t find that file to show.
@louicoder
louicoder / randomNames.js
Last active January 27, 2022 08:55
Generate Random names
const names = [ 'jo', 'caleb', 'trinat' ]; // Array of all names you like to include
generateRandomName(names);
/**
* Generate a random name from a list of names created
* @param {Array} nameList
* @returns String finalName
*/
function generateRandomName (nameList) {
@louicoder
louicoder / sockets-react-native.js
Created October 14, 2021 10:26
React native websocket connection
import { Text, View, StyleSheet, Alert } from 'react-native';
navigator.__defineGetter__('userAgent', function () {
// you have to import rect native first !!
return 'react-native';
});
import SocketIOClient from 'socket.io-client/dist/socket.io.js';
//
@louicoder
louicoder / Debounce.js
Last active September 14, 2022 13:12
Debounce functionality for auto suggestion while typing
// function called when debounce executes
// Usually this is where you call you external api
const onDebounce = () => {
console.log('calling api....');
};
// Function that handles on change for your iinput
const onValueChanged = (e) => {
console.log('changing state....');
setState(e.target.value);
@louicoder
louicoder / FlatListGrid.js
Last active July 30, 2021 08:08
Flatlist 3 colmun grid view
import React from 'react';
import { View, Text } from 'react-native';
const FlatListGrid = ({ onEndReached }) => {
const numColums = 3;
return (
<FlatList
style={{ flex: 1 }}
// refreshing={loading}
@louicoder
louicoder / StickyView.js
Last active July 28, 2021 07:13
A sticky View for react native that sticks at the bottom of screen
import React from 'react';
import { StyleSheet, KeyboardAvoidingView, Platform, NativeModules } from 'react-native';
const { StatusBarManager } = NativeModules;
let statusBarHeight = 0;
if (Platform.OS === 'ios') {
StatusBarManager.getHeight((statusBarFrameData) => {
statusBarHeight = statusBarFrameData.height;
});