Redux, JavaScript uygulamaları için öngörülebilir bir durum kapsayıcısıdır.
Tutarlı davranan, farklı ortamlarda (istemci, sunucu ve yerel) çalışan ve test etmesi kolay uygulamalar yazmanıza yardımcı olur. Bunun da ötesinde, harika bir geliştirici deneyimi sağlar.
Redux'u react native içinde kurmak için. Aşağıdaki paketleri kuracağız.
yarn add react-redux redux redux-persist redux-thunk @react-native-community/async-storage
export const SAVE_TOKEN = 'SAVE_TOKEN';
import { SAVE_TOKEN } from './types';
export const saveToken = (key) => ({
type: SAVE_TOKEN,
payload: key
});
import { SAVE_TOKEN } from '../actions/types';
const initialState = {
token: ''
};
const Reducer = (state = initialState, action) => {
switch (action.type) {
case SAVE_TOKEN:
return {
...state,
token: action.payload,
};
default:
return state;
}
};
export default Reducer;
import {applyMiddleware, combineReducers, createStore, compose} from 'redux';
import thunk from 'redux-thunk';
import {persistStore, persistReducer} from 'redux-persist';
import AsyncStorage from '@react-native-community/async-storage';
import Reducer from './reducers';
// Redux Debugger
let composeEnhancer = compose;
if (__DEV__) {
composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
}
const Reducers = {
appData: Reducer
};
const persistConfig = {
key: 'root',
storage: AsyncStorage,
blacklist: ['navigation'], // navigation will not be persisted
// stateReconciler: autoMergeLevel2,
// timeout: 100000,
};
const persistedReducer = persistReducer(
persistConfig,
combineReducers(Reducers),
);
export const Store = createStore(
persistedReducer,composeEnhancer(applyMiddleware(thunk))
);
export const persistor = persistStore(Store);
import React from 'react';
import {Route} from './src/navigation/routes';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/integration/react';
import {Store, persistor} from './src/store';
import {StatusBar} from 'react-native';
import RNBootSplash from 'react-native-bootsplash';
const App = () => {
RNBootSplash.hide();
return (
<Provider store={Store}>
<PersistGate loading={null} persistor={persistor}>
<StatusBar backgroundColor="#000" barStyle="light-content" /
<Route />
</PersistGate>
</Provider>
);
};
export default App;
import React, {useState, useEffect} from 'react';
import {persistor} from '../store';
import * as wpActions from '../../store/actions';
import {useSelector, useDispatch} from 'react-redux';
const Login = ({navigation}) => {
const dispatch = useDispatch();
const [code, setCode] = useState('');
const details = useSelector((state) => state.appData.details);
console.log(details);
// Comment this code if not clearing database.
useEffect(() => {
persistor.purge;
console.log('purging database');
}, []);
const sendToken=()=>{
dispatch(wpActions.saveToken(code))
}
yarn add @react-native-community/async-storage @react-native-community/masked-view @react-navigation/drawer @react-navigation/native @react-navigation/stack react-native-gesture-handler react-native-reanimated react-native-responsive-screen react-native-safe-area-context react-native-screens react-native-vector-icons react-redux redux redux-persist redux-thunk
React'te bir diziyi eşlerken "her öğenin benzersiz bir anahtarı olmalıdır" uyarı mesajını görmezden gelme eğiliminde olan biriyseniz, bu uyarının neden en başta ortaya çıktığını anlamak için bir dakikanızı ayırmanız önemlidir. React'te, “Array.
7 yıldan fazla deneyime sahip bir Android geliştiricisi olarak Java ve Kotlin dünyasına her zaman ilgi duymuşumdur. Ancak yaklaşık bir yıl önce, kendimi yeni bir şey keşfetmek isterken buldum — ve işte o zaman React Native'e dalmaya başladım.
Kaç kez bir plastik şişeyi, cam kavanozu, alüminyum kutuyu veya yeşil enerji paketini iki kere düşünmeden çöpe attınız? Kaç kez geri dönüşüm karşılığında bir şey alabilmeyi diledin? Çoğu insan gibiyseniz, cevap muhtemelen birçok kez. Geri dönüşüm genellikle herhangi bir acil veya somut fayda sağlamayan bir güçlük, angarya veya görev olarak görülür.
Geçen hafta PressGazette (İngiliz medya haber sitesi) aracılığıyla gönderilen bir basın bildirisi fark ettim. Makale, Scandi podcast barındırma ve reklamcılık şirketi Acast'ın podcasting alanında "muhtemelen en etkili" yayıncılardan oluşan bir konsorsiyuma liderlik edeceğini duyurdu.
Günümüzün hızlı tempolu ve rekabetçi dünyasında, kişinin kariyeri kişisel gelişim, finansal istikrar ve genel yaşam memnuniyetinde önemli bir rol oynamaktadır. Bununla birlikte, birçok kişi profesyonel yaşamlarında giderek tükenmekte olan amansız bir durgunluk ve tatminsizlik döngüsüne kapılmış durumda.