helpers.js
export const addListResult = (state, key)=>{
state.LISTS.push({key:key, createdAt: moment()})
return state
}
store.js
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { ADD_LIST } from "./constants.js";
import { addListResult } from "./helpers";
const initialState = {
LISTS: [],
WORDS: [],
loading: false,
error: null
}
export const reducer = (state=initialState, {type, payload}) => {
switch (type){
case ADD_LIST:
return addListResult(state,payload)
}
}
export default createStore(reducer, applyMiddleware(thunk))
actions.js
import { ADD_LIST } from "./constants.js"
export const addList = function(arg){
return {
type: ADD_LIST,
payload: arg
}
}
constants.js
export const ADD_LIST = 'ADD_LIST'
export const LISTS = 'LISTS'
export const WORDS = 'WORDS'
App.js
import React, {useEffect, useState} from 'react';
import { View, Text, StyleSheet } from 'react-native';
import * as Font from 'expo-font'
import { ActivityIndicator } from 'react-native';
import fonticons from './src/assets/fonts/fontIcon/fonticons.ttf'
import RobotoBold from './src/assets/fonts/Roboto/Roboto-Bold.ttf'
import RobotoMedium from './src/assets/fonts/Roboto/Roboto-Medium.ttf'
import RobotoRegular from './src/assets/fonts/Roboto/Roboto-Regular.ttf'
export default function App() {
const [show, setShow] = useState(false)
useEffect(function asd(){
const fontLoads = async function(){
await Font.loadAsync({
fonticons,
RobotoBold,
RobotoMedium,
RobotoRegular
})
setShow(true)
}
fontLoads()
}, [])
if(!show){
return (
<View style={styles.container}><ActivityIndicator size='small' /></View>
)
}
else{
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});