├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.css ├── App.js ├── App.test.js ├── context.js ├── index.css ├── index.js ├── logo.svg ├── reportWebVitals.js └── setupTests.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Javascript Context Api Uygulaması 2 | 3 |

4 | 5 |

6 | 7 | ## Context Api 8 | 9 | Context, prop’ları her seviyede manuel olarak geçmek zorunda kalmadan bileşen ağacı üzerinden veri iletmenin bir yolunu sağlar. 10 | 11 | ### Projenin Amacı Nedir ? 12 | 13 | React Javascript ile useContext() & useReducer hooks kullanarak sizlere global state management Context Api nasıl kullanacağımızı paylaşıyorum. 14 | Bu projede tema yönetimini dark mode yada light bilgisine göre arayüzü nasıl değiştirebileceğimizi context bulunan mesajı nasıl değiştirebileceğimizi basit bir örnek ile sizlere paylaşıyorum. 15 | 16 | ### Context Api Neden Kullanılırız? 17 | 18 | Tipik bir React uygulamasında veri prop’lar aracılığıyla yukarıdan aşağıya aktarılır (üst bileşenlerden alt bileşenlere). Fakat bu tür bir kullanım, uygulamadaki birçok bileşen tarafından ihtiyaç duyulan belirli tipteki prop’lar (örneğin; lokalizasyon, arayüz teması) için kullanışsız olabilir. Context, bileşen ağacın her bir seviyesi üzerinden açıkça bir prop geçirmeden, bileşenler arasında bu gibi değerleri paylaşmanın bir yolunu sağlar. 19 | 20 | ## Contact Us 21 | 22 | - 🌱 I’m currently learning **Solidity** 23 | 24 | - 📝 I regularly write articles on [https://www.linkedin.com/in/furkanturkyilmaz/detail/recent-activity/shares/](https://www.linkedin.com/in/furkanturkyilmaz/detail/recent-activity/shares/) 25 | 26 | - 🔮 I develop dApps project with React Javascript & React Native. 27 | 28 | - 🤭 I love Web 3.0 Technology. 29 | 30 | - 💡 I'm mentor for Javascript, React , React Native,Blockchain , Solidity, Web 3 31 | 32 | - 💬 Ask me about **React JS,React Native,Javascript,Solidity,Blockchain,Web 3** 33 | 34 | - 📫 Email **trkyilmazfurkan@gmail.com** 35 | 36 | - furkanturkyilmaz LinkedIn **https://www.linkedin.com/in/furkanturkyilmaz/** 37 | 38 | - furkanturkyilmaz GitHub **https://github.com/fturkyilmaz** 39 | 40 | 41 | ## React Native Ücretsiz Eğitim İçerikleri 42 | 43 | React Native & React Js düzenlemiş olduğum bootcamp ve coding challenge kayıtlarını sizlere paylaşıyorum. 44 | 45 | React Native Bootcamp : [https://www.youtube.com/playlist?list=PLT_pHf0diFdMX1AgnNOUqRkO9FvloedXG](https://www.youtube.com/playlist?list=PLT_pHf0diFdMX1AgnNOUqRkO9FvloedXG) 46 | 47 | React Native Coding Challenge : [https://www.youtube.com/playlist?list=PLT_pHf0diFdMvewldSeN-dD-L9YVq1xbm](https://www.youtube.com/playlist?list=PLT_pHf0diFdMvewldSeN-dD-L9YVq1xbm) 48 | 49 | 50 | **React Native,React Js ,Web 3.0 bootcamp ve workshop düzenlemek isterseniz benimle iletişime geçebilirsiniz.**   51 | 52 | **React Native,React Js ,Javascript ekosisteminde ücretli mentorlük hizmeti vermekteyim.**   53 | 54 | 55 | #web3 #javascript #blockchain #reactnative #reactjs #solidity #web3 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-javascript-context-api", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.2", 7 | "@testing-library/react": "^12.1.4", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^17.0.2", 10 | "react-dom": "^17.0.2", 11 | "react-scripts": "5.0.0", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fturkyilmaz/react-javascript-context-api/308f9bc29b7cb04795213ce09fda06dc560133a0/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 15 | 16 | 25 | Furkan Türkyılmaz Context Api 26 | 27 | 28 | 29 | 30 |
31 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fturkyilmaz/react-javascript-context-api/308f9bc29b7cb04795213ce09fda06dc560133a0/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fturkyilmaz/react-javascript-context-api/308f9bc29b7cb04795213ce09fda06dc560133a0/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | body.light { 11 | background: "white"; 12 | color: "#333"; 13 | } 14 | 15 | body.dark { 16 | background-color: #282c34; 17 | color: #eee; 18 | } 19 | 20 | @media (prefers-reduced-motion: no-preference) { 21 | .App-logo { 22 | animation: App-logo-spin infinite 20s linear; 23 | } 24 | } 25 | 26 | .App-header { 27 | min-height: 100vh; 28 | display: flex; 29 | flex-direction: column; 30 | align-items: center; 31 | justify-content: center; 32 | font-size: calc(10px + 2vmin); 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | padding-top: 1.5rem; 38 | } 39 | 40 | @keyframes App-logo-spin { 41 | from { 42 | transform: rotate(0deg); 43 | } 44 | to { 45 | transform: rotate(360deg); 46 | } 47 | } 48 | 49 | .buttonContainer { 50 | display: flex; 51 | flex-direction: row; 52 | align-items: center; 53 | justify-content: center; 54 | } 55 | 56 | .button { 57 | background-color: #61dafb; 58 | border-radius: 10px; 59 | border: none; 60 | color: white; 61 | padding: 15px 32px 15px 32px; 62 | margin: 10px; 63 | text-align: center; 64 | text-decoration: none; 65 | display: inline-block; 66 | font-size: 18px; 67 | font-weight: bold; 68 | } 69 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect } from "react"; 2 | import logo from "./logo.svg"; 3 | import "./App.css"; 4 | import { useContext, MainContext } from "../src/context"; 5 | 6 | function App() { 7 | const [state, dispatch] = useContext(MainContext); 8 | 9 | const { theme, message, linkedin } = state; 10 | 11 | console.log("Context", state); 12 | 13 | useEffect(() => { 14 | document.body.className = theme; 15 | }, [theme]); 16 | 17 | return ( 18 |
19 |
20 | logo 21 |

{message}

22 | 23 |
24 | 29 | 30 | 40 |
41 | 46 | LinkedIn 47 | 48 |
49 |
50 | ); 51 | } 52 | 53 | export default App; 54 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/context.js: -------------------------------------------------------------------------------- 1 | import { createContext, useContext, useReducer } from "react"; 2 | 3 | //Context oluşturuyoruz. 4 | 5 | const MainContext = createContext(); 6 | 7 | const initialState = { 8 | theme: "light", 9 | message: 10 | "Furkan Türkyılmaz Context Api Global State Management Simple Example", 11 | linkedin: "https://www.linkedin.com/in/furkanturkyilmaz/", 12 | }; 13 | 14 | // Reducer Method tanımlıyoruz. 15 | 16 | const reducer = (state, action) => { 17 | switch (action.type) { 18 | case "TOGGLE_THEME": 19 | return { 20 | ...state, 21 | theme: state.theme === "light" ? "dark" : "light", 22 | }; 23 | 24 | case "TOGGLE_MESSAGE": 25 | return { 26 | ...state, 27 | message: action.payload, 28 | }; 29 | 30 | default: 31 | return state; 32 | } 33 | }; 34 | 35 | //Provider içinde state ve dispatch değişkenlerini kullanıyoruz. 36 | 37 | const ContextProvider = ({ children }) => { 38 | const [state, dispatch] = useReducer(reducer, initialState); 39 | 40 | return ( 41 | 42 | {children} 43 | 44 | ); 45 | }; 46 | 47 | export { MainContext, ContextProvider, useContext }; 48 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | import { ContextProvider } from "./context"; 7 | 8 | // Projemizi ContextProvider ile bağlayalım. 9 | 10 | ReactDOM.render( 11 | 12 | 13 | 14 | 15 | , 16 | document.getElementById("root") 17 | ); 18 | 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | --------------------------------------------------------------------------------