Skip to content

Commit 9c550f3

Browse files
committed
Fleiri síður og uppfærslur
1 parent a895507 commit 9c550f3

File tree

7 files changed

+124
-119
lines changed

7 files changed

+124
-119
lines changed

src/components/Layout/HomeContent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ export function HomeContent() {
139139
type="primary"
140140
size="lg"
141141
className="w-full sm:w-auto justify-center"
142-
label="Lærðu React">
143-
Lærðu React
142+
label="Lærðu á React">
143+
Lærðu á React
144144
</ButtonLink>
145145
<ButtonLink
146146
href={'/reference/react'}
Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,156 @@
11
---
2-
title: Add React to an Existing Project
2+
title: Innsetning á React í tiltæku verkefni
33
---
44

55
<Intro>
66

7-
If you want to add some interactivity to your existing project, you don't have to rewrite it in React. Add React to your existing stack, and render interactive React components anywhere.
7+
Þú þarft ekki að endurskrifa tiltækt verkefni til að auka gagnvirknina. Þú getur bætt React við núverandi tæknistafla og birt React íhluti hvar sem er.
88

99
</Intro>
1010

1111
<Note>
1212

13-
**You need to install [Node.js](https://nodejs.org/en/) for local development.** Although you can [try React](/learn/installation#try-react) online or with a simple HTML page, realistically most JavaScript tooling you'll want to use for development requires Node.js.
13+
**Þú verður að innsetja [Node.js](https://nodejs.org/en/) fyrir staðbundna þróun.** Þrátt fyrir að þú getir [prófað React](/learn/installation#try-react) á Netinu eða með einfaldri HTML síðu þá munu flest tólin sem þú þarft í þróunarumhverfinu þurfa á Node.js að halda.
1414

1515
</Note>
1616

17-
## Using React for an entire subroute of your existing website {/*using-react-for-an-entire-subroute-of-your-existing-website*/}
17+
## Notkun á React fyrir undirsíðu á núverandi síðu {/*using-react-for-an-entire-subroute-of-your-existing-website*/}
1818

19-
Let's say you have an existing web app at `example.com` built with another server technology (like Rails), and you want to implement all routes starting with `example.com/some-app/` fully with React.
19+
Gefum okkur að þú sért með tiltæka vefþjónustu á `example.com` sem var skrifuð með bakendaþjónustu eins og Rails, og þú viljir útfæra allar beiningar sem byrja á `example.com/eitthvað-forrit` með React.
2020

21-
Here's how we recommend to set it up:
21+
Þá mælum við með þessari nálgun:
2222

23-
1. **Build the React part of your app** using one of the [React-based frameworks](/learn/start-a-new-react-project).
24-
2. **Specify `/some-app` as the *base path*** in your framework's configuration (here's how: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
25-
3. **Configure your server or a proxy** so that all requests under `/some-app/` are handled by your React app.
23+
1. **Smíðaðu React hlutann** með einhverju [React rammakerfi](/learn/start-a-new-react-project).
24+
2. **Tilgreindu `/eitthvað-forrit` sem *grunnslóð*** í stillingum rammans sem þú valdir (sjá hér: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath) eða [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
25+
3. **Stilltu vefþjóninn eða vefselið** á þann veg að allar beiðnir sem hefjist á `/eitthvað-forrit/` séu birtar í React forritinu þínu.
2626

27-
This ensures the React part of your app can [benefit from the best practices](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) baked into those frameworks.
27+
Þetta tryggir að React hlutinn í vefsíðunni þinni [fylgi þróunarstöðlunum](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) sem eru innbyggðir í þessum römmum.
2828

29-
Many React-based frameworks are full-stack and let your React app take advantage of the server. However, you can use the same approach even if you can't or don't want to run JavaScript on the server. In that case, serve the HTML/CSS/JS export ([`next export` output](https://nextjs.org/docs/advanced-features/static-html-export) for Next.js, default for Gatsby) at `/some-app/` instead.
29+
Sum React rammakerfi eru heilstafla (e. full-stack) og gera þér kleift að skrifa bakendakóða líka. Hvort sem það er eitthvað sem þú vilt nýta þer eða ekki þá geturðu fylgt sömu nálgunum. Til dæmis er hægt að birta kyrrlegt HTML, CSS, og JS ([`next export` úttak](https://nextjs.org/docs/advanced-features/static-html-export) í Next.js, sjálfgefið í Gatsby) á síðunni `/eitthvað-forrit`.
3030

31-
## Using React for a part of your existing page {/*using-react-for-a-part-of-your-existing-page*/}
31+
## Notkun React á hluta vefsíðu {/*using-react-for-a-part-of-your-existing-page*/}
3232

33-
Let's say you have an existing page built with another technology (either a server one like Rails, or a client one like Backbone), and you want to render interactive React components somewhere on that page. That's a common way to integrate React--in fact, it's how most React usage looked at Meta for many years!
33+
Gefum okkur að þú sért með vefsíðu sem er skrifuð í annarri tækni (annaðvort bakendatækni eins og Rails eða framendatækni eins og Backbone), og að þú viljir birta gagnvirka React íhluti einhvers staðar á síðunni. Þetta er tiltölulega algeng nálgun til að nota React--í raun var það á tímabili nákvæmlega þannig sem Meta notaði React!
3434

35-
You can do this in two steps:
35+
Þú getur gert þetta í tveimur skrefum:
3636

37-
1. **Set up a JavaScript environment** that lets you use the [JSX syntax](/learn/writing-markup-with-jsx), split your code into modules with the [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) / [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) syntax, and use packages (for example, React) from the [npm](https://www.npmjs.com/) package registry.
38-
2. **Render your React components** where you want to see them on the page.
37+
1. **Útbúðu JavaScript umhverfi** sem gerir þér kleift að nota [JSX málskipan](/learn/writing-markup-with-jsx), deila kóðanum þínum í einingar með [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) og [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) málskipan, og notaðu forritasöfn (til dæmis, React) frá [npm](https://www.npmjs.com/) pakkaskránni.
38+
2. **Birtu React íhlutina þína** þar sem þú vilt hafa þá á síðunni.
3939

40-
The exact approach depends on your existing page setup, so let's walk through some details.
40+
Nákvæm útfærsla á þessu veltur á núverandi uppsetningu hjá þér, svo við skulum fara aðeins nánar út í smáatriðin.
4141

42-
### Step 1: Set up a modular JavaScript environment {/*step-1-set-up-a-modular-javascript-environment*/}
42+
### Fyrsta skref: Skiptu JavaScript umhverfinu þínu í einingar {/*step-1-set-up-a-modular-javascript-environment*/}
4343

44-
A modular JavaScript environment lets you write your React components in individual files, as opposed to writing all of your code in a single file. It also lets you use all the wonderful packages published by other developers on the [npm](https://www.npmjs.com/) registry--including React itself! How you do this depends on your existing setup:
44+
Með því að skipta JavaScript kóða í einingar er hægt að nota margar skrár í stað þess að skrifa allan kóðann í eina skrá. Það gerir þér líka kleift að nota öll forritasöfnin sem eru aðgengileg á [npm](https://www.npmjs.com/) pakkaskránni--þar á meðal React sjálft! Nálgunin veltur á núverandi uppsetningu:
4545

46-
* **If your app is already split into files that use `import` statements,** try to use the setup you already have. Check whether writing `<div />` in your JS code causes a syntax error. If it causes a syntax error, you might need to [transform your JavaScript code with Babel](https://babeljs.io/setup), and enable the [Babel React preset](https://babeljs.io/docs/babel-preset-react) to use JSX.
46+
* **Ef vefurinn þinn er nú þegar skiptur í mismunandi skrár sem nota `import` setningar** reyndu þá að halda áfram að nota sama kerfi. Athugaðu hvort það virki að skrifa `<div />` án þess að það komi málskipanvilla. Ef þetta veldur villu þá kann að vera að þú þurfir að [umbreyta JavaScript kóðanum með Babel](https://babeljs.io/setup), og virkja [Babel React forstillinguna](https://babeljs.io/docs/babel-preset-react) til að nota JSX.
4747

48-
* **If your app doesn't have an existing setup for compiling JavaScript modules,** set it up with [Vite](https://vitejs.dev/). The Vite community maintains [many integrations with backend frameworks](https://github.com/vitejs/awesome-vite#integrations-with-backends), including Rails, Django, and Laravel. If your backend framework is not listed, [follow this guide](https://vitejs.dev/guide/backend-integration.html) to manually integrate Vite builds with your backend.
48+
* **Ef vefurinn þinn er ekki með neitt kerfi til að þýða JavaScript einingar** þá skaltu prófa að nota [Vite](https://vitejs.dev/) til þess. Vite samfélagið viðheldur [margs konar samtengingum við bakendaramma](https://github.com/vitejs/awesome-vite#integrations-with-backends), m.a. Rails, Django, og Laravel. Ef bakendaramminn þinn er ekki útlistaður þá skaltu [fylgja þessum leiðbeiningum](https://vitejs.dev/guide/backend-integration.html) til að tengja Vite við bakendann þinn handvirkt.
4949

50-
To check whether your setup works, run this command in your project folder:
50+
Til að kanna hvort kerfið þitt virki geturðu keyrt eftirfarandi skipun í aðalmöppu verkefnisins:
5151

5252
<TerminalBlock>
5353
npm install react react-dom
5454
</TerminalBlock>
5555

56-
Then add these lines of code at the top of your main JavaScript file (it might be called `index.js` or `main.js`):
56+
Bættu svo þessum kóða efst í aðal JavaScript skránni (hún ætti að heita `index.js` eða kannski `main.js`):
5757

5858
<Sandpack>
5959

6060
```html index.html hidden
6161
<!DOCTYPE html>
6262
<html>
63-
<head><title>My app</title></head>
63+
<head><title>Vefurinn minn</title></head>
6464
<body>
65-
<!-- Your existing page content (in this example, it gets replaced) -->
65+
<!-- Núverandi efni (í þessu tilfelli skiptum við því algjörlega út) -->
6666
</body>
6767
</html>
6868
```
6969

7070
```js index.js active
7171
import { createRoot } from 'react-dom/client';
7272

73-
// Clear the existing HTML content
73+
// Fjarlægjum núverandi efni.
7474
document.body.innerHTML = '<div id="app"></div>';
7575

76-
// Render your React component instead
76+
// Birtum React íhlut þess í stað.
7777
const root = createRoot(document.getElementById('app'));
78-
root.render(<h1>Hello, world</h1>);
78+
root.render(<h1>Halló, heimur!</h1>);
7979
```
8080

8181
</Sandpack>
8282

83-
If the entire content of your page was replaced by a "Hello, world!", everything worked! Keep reading.
83+
Ef efnið á síðunni hvarf og „Halló, heimur!“ kom þess í stað þá virkaði breytingin og þú getur haldið áfram að lesa þessar leiðbeiningar.
8484

8585
<Note>
8686

87-
Integrating a modular JavaScript environment into an existing project for the first time can feel intimidating, but it's worth it! If you get stuck, try our [community resources](/community) or the [Vite Chat](https://chat.vitejs.dev/).
87+
Fyrst um sinn getur verið hálfógnvekjandi að reyna að útfæra einingamiðað JavaScript umhverfi, en það er þess virði! Prófaðu að skoða [efnið frá React samfélaginu](/community) eða [Vite Chat](https://chat.vitejs.dev/) ef þér finnst þú ekki ná árangri.
8888

8989
</Note>
9090

91-
### Step 2: Render React components anywhere on the page {/*step-2-render-react-components-anywhere-on-the-page*/}
91+
### Annað skref: Birtu React íhluti hvar sem er á síðunni {/*step-2-render-react-components-anywhere-on-the-page*/}
9292

93-
In the previous step, you put this code at the top of your main file:
93+
Í skrefinu á undan settum við þennan kóða efst í aðalskránni:
9494

95-
```js
95+
```js index.js active
9696
import { createRoot } from 'react-dom/client';
9797

98-
// Clear the existing HTML content
98+
// Fjarlægjum núverandi efni.
9999
document.body.innerHTML = '<div id="app"></div>';
100100

101-
// Render your React component instead
101+
// Birtum React íhlut þess í stað.
102102
const root = createRoot(document.getElementById('app'));
103-
root.render(<h1>Hello, world</h1>);
103+
root.render(<h1>Halló, heimur!</h1>);
104104
```
105105

106-
Of course, you don't actually want to clear the existing HTML content!
106+
En að sjálfsögðu viljum við ekki henda öllu efninu af síðunni!
107107

108-
Delete this code.
108+
Eyddu þessum kóða.
109109

110110
Instead, you probably want to render your React components in specific places in your HTML. Open your HTML page (or the server templates that generate it) and add a unique [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) attribute to any tag, for example:
111+
Þess í stað viltu sennilega birta React íhluti á ákveðnum stöðum. Opnaðu HTML síðuna (eða sniðmátið sem bakendinn útbýr) og bættu við einstöku [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) eigindi við hvaða merki sem er á síðunni, til dæmis:
111112

112113
```html
113-
<!-- ... somewhere in your html ... -->
114-
<nav id="navigation"></nav>
115-
<!-- ... more html ... -->
114+
<!-- ... einhvers staðar í skránni ... -->
115+
<nav id="valmynd"></nav>
116+
<!-- ... meira HTML ... -->
116117
```
117118

118-
This lets you find that HTML element with [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) and pass it to [`createRoot`](/reference/react-dom/client/createRoot) so that you can render your own React component inside:
119+
Með þessu móti geturðu fundið eininguna í HTML skránni með [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) og fært [`createRoot`](/reference/react-dom/client/createRoot) hana til að birta React íhlut inni í henni:
119120

120121
<Sandpack>
121122

122123
```html index.html
123124
<!DOCTYPE html>
124125
<html>
125-
<head><title>My app</title></head>
126+
<head><title>Vefurinn minn</title></head>
126127
<body>
127-
<p>This paragraph is a part of HTML.</p>
128-
<nav id="navigation"></nav>
129-
<p>This paragraph is also a part of HTML.</p>
128+
<p>Þessi efnisgrein er hluti af HTML skránni.</p>
129+
<nav id="valmynd"></nav>
130+
<p>Þessi efnisgrein er líka hluti af HTML skránni.</p>
130131
</body>
131132
</html>
132133
```
133134

134135
```js index.js active
135136
import { createRoot } from 'react-dom/client';
136137

137-
function NavigationBar() {
138-
// TODO: Actually implement a navigation bar
139-
return <h1>Hello from React!</h1>;
138+
function Valmynd() {
139+
// Síðar: útfærum raunverulegu valmyndina!
140+
return <h1>Halló frá React!</h1>;
140141
}
141142

142-
const domNode = document.getElementById('navigation');
143-
const root = createRoot(domNode);
144-
root.render(<NavigationBar />);
143+
const domHnútur = document.getElementById('valmynd');
144+
const rót = createRoot(domHnútur);
145+
t.render(<Valmynd />);
145146
```
146147

147148
</Sandpack>
148149

149-
Notice how the original HTML content from `index.html` is preserved, but your own `NavigationBar` React component now appears inside the `<nav id="navigation">` from your HTML. Read the [`createRoot` usage documentation](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) to learn more about rendering React components inside an existing HTML page.
150+
Taktu eftir því að upprunalega HTML efnið í `index.html` er enn þar, en React íhluturinn `Valmynd` er nú innan í `<nav id="valmynd">` í HTML skránni. Lestu [skjalbúnaðinn fyrir `createRoot`](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) til að kynna þér nánar hvernig hægt er að birta React íhluti inni í HTML síðu.
150151

151-
When you adopt React in an existing project, it's common to start with small interactive components (like buttons), and then gradually keep "moving upwards" until eventually your entire page is built with React. If you ever reach that point, we recommend migrating to [a React framework](/learn/start-a-new-react-project) right after to get the most out of React.
152+
Það er algengt að byrja á að útfæra smærri gagnvirka íhluti eins og takka og hægt og rólega „færa sig ofar“ þar til öll síðan er útfærð í React. Ef þú nálgast það stig þá mælum við með því að flytja þig yfir í [React ramma](/learn/start-a-new-react-project) til að nýta React sem best.
152153

153-
## Using React Native in an existing native mobile app {/*using-react-native-in-an-existing-native-mobile-app*/}
154+
## Notkun á React Native í tiltæku forriti á heimavangi {/*using-react-native-in-an-existing-native-mobile-app*/}
154155

155-
[React Native](https://reactnative.dev/) can also be integrated into existing native apps incrementally. If you have an existing native app for Android (Java or Kotlin) or iOS (Objective-C or Swift), [follow this guide](https://reactnative.dev/docs/integration-with-existing-apps) to add a React Native screen to it.
156+
Það er einnig hægt að byrja að nota [React Native](https://reactnative.dev/) hægt og rólega. Ef þú ert með forrit fyrir Android (í Java eða Kotlin) eða iOS (í Objective-C eða Swift), [fylgdu þá þessum leiðbeiningum](https://reactnative.dev/docs/integration-with-existing-apps) til að bæta við virkni í React Native.

0 commit comments

Comments
 (0)