Después de introducir redux en mi aplicación expo nativa de reacción, por alguna razón, cada vez que intento interactuar con la base de datos, hace que mi aplicación deje de funcionar. No tengo idea de qué podría estar causando esto y no pude encontrar nada al respecto en línea.
Los archivos Redux son los siguientes:
acciones.js:
export const SET_SELECTED_PLAYERS = "SET_SELECTED_PLAYERS" export const SET_PLAYERS = "SET_PLAYERS" export const SET_SELECTED_COURSE = "SET_SELECTED_COURSE" export const SET_COURSES = "SET_COURSES" //Player actions export const setPlayers = (players) => ( { type: SET_PLAYERS, payload: players, } ) export const setSelectedPlayers = (players) => ( ({ type: SET_SELECTED_PLAYERS, payload: players, }) ) export const setSelectedCourse = (course) => ({ type: SET_SELECTED_COURSE, payload: course, }) export const setCourses = (courses) => ({ type: SET_COURSES, payload: courses, })reductores.js:
import { SET_PLAYERS, SET_SELECTED_PLAYERS, SET_SELECTED_COURSE, SET_COURSES } from "./actions" const initialState = { players: [], selectedPlayers: [], courses: [], selectedCourse: null, round: {} } export const playerReducer = (state = initialState, action) => { switch (action.type) { case SET_PLAYERS: return { ...state, players: action.payload } case SET_SELECTED_PLAYERS: return { ...state, selectedPlayers: action.payload } default: return state } } export const courseReducer = (state = initialState, action) => { switch (action.type) { case SET_SELECTED_COURSE: return { ...state, selectedCourse: action.payload } case SET_COURSES: return { ...state, courses: action.payload } default: return state } }tienda.js:
import { createStore, combineReducers, applyMiddleware } from "redux"; import { courseReducer, playerReducer } from "./reducers"; const rootReducer = combineReducers({ playerReducer, courseReducer }) export const Store = createStore(rootReducer)Y la base de datos sqlite se usa en un componente así:
const dispatch = useDispatch() const db = SQLite.openDatabase("players.db") useEffect(() => { db.transaction(tx => { tx.executeSql("SELECT * FROM Player", [], (trans, result) => { dispatch(setPlayers(result.rows._array)) }) }) }, [])Se ha creado Table for Player, la aplicación funcionó bien antes de presentar Redux. Mi aplicación interactúa con Firebase y cuando obtiene datos de la nube, Redux no tiene problemas. No tengo idea de qué problemas podría tener con SQLite. Gracias de antemano por cualquier ayuda.