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 grouped = array.reduce((obj, item) => { | |
const key = item.age; | |
if (!obj[key]) { | |
obj[key] = []; | |
} | |
obj[key].push(item); | |
return obj; |
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
// 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 }; | |
}; |
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
// 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> |
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
/** | |
* @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 |
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 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) { |
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 { 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'; | |
// |
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
// 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); |
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 React from 'react'; | |
import { View, Text } from 'react-native'; | |
const FlatListGrid = ({ onEndReached }) => { | |
const numColums = 3; | |
return ( | |
<FlatList | |
style={{ flex: 1 }} | |
// refreshing={loading} |
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 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; | |
}); |