Skip to content

Instantly share code, notes, and snippets.

View pavinduLakshan's full-sized avatar
🎯
Focusing

Pavindu Lakshan pavinduLakshan

🎯
Focusing
View GitHub Profile
function Profile({ navigation }) {
React.useEffect(() => {
const unsubscribe = navigation.addListener('focus', () => {
// Fetch profile data
});
return unsubscribe;
}, [navigation]);
return <ProfileContent />;
const initState = {
theme: 'default'
}
const Reducer = (state=initState,action) => {
switch (action.type){
case "CHANGE_THEME":
return {
...state,
import React from 'react'
import { useDispatch } from 'react-redux'
const AnotherChildComponent = () => {
const dispatch = useDispatch()
function changeTheme (theme) {
dispatch({
type: 'CHANGE_THEME',
theme: theme
import React, { useState } from 'react'
const Component1 = props => {
return <p>{props.theme}</p>
}
const Component2 = props => {
return <Component1 theme={props.theme}/>
}
const initUserState = {
isAuth: false,
isAuthModalOpen: false
}
const initGalleryState = {
selectedPhotoURL: ""
}
const UserReducer = (state=initUserState,action) => {
import React,{useState} from 'react';
import {useSelector} from 'react-redux';
const ChildComponent = () => {
const appTheme = useSelector(state => state.theme)
return (
<div>
<p>{appTheme}</p>
</div>
)
const initState = {
theme: 'default'
}
const Reducer = (state=initState,action) => {
return state;
}
export default Reducer
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
import Reducer from './Reducer'
import { createStore } from 'redux';
import { Provider } from 'react-redux';
const store = createStore(Reducer);
import React from 'react';
import './App.css';
import PaymentModal from './PaymentModal/PaymentModal';
function App() {
return (
<div className="App">
<PaymentModal
// Use a unique value for the orderId
orderId={45896588}
button {
padding: 2%;
background-color: yellow;
}