Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
intro-react
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
javascript
intro-react
Commits
0cf799f5
Commit
0cf799f5
authored
1 year ago
by
Jean-Christophe
Browse files
Options
Downloads
Patches
Plain Diff
premiers composants sans état
parent
396c3523
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+3
-1
3 additions, 1 deletion
README.md
src/components/first.jsx
+12
-0
12 additions, 0 deletions
src/components/first.jsx
src/components/second.jsx
+16
-0
16 additions, 0 deletions
src/components/second.jsx
src/scripts/main.js
+6
-10
6 additions, 10 deletions
src/scripts/main.js
with
37 additions
and
11 deletions
README.md
+
3
−
1
View file @
0cf799f5
...
...
@@ -28,6 +28,8 @@ où `tag` peut prendre comme valeur :
voir
`/src/scripts/main.js`
et le point d'insertion
`#insertReactHere`
dans
`/src/index.html`
*
`v0.5`
: second exemple avec création d'un emboitement d'éléments
*
`v1`
: premier exemple avec la syntaxe JSX
*
`v2`
: premiers composants sans état
voir
`/src/components/first.jsx`
,
`/src/components/second.jsx`
et son utilisation dans
`/src/mains.js`
Faire
```git checkout main```
pour revenir à la version finale.
This diff is collapsed.
Click to expand it.
src/components/first.jsx
0 → 100644
+
12
−
0
View file @
0cf799f5
/*
* define a stateless React component
*/
const
First
=
()
=>
<
article
>
<
h3
>
React
<
strong
>
First component
</
strong
>
in action, using JSX
</
h3
>
<
div
>
this div is defined by the
<
code
>
First
</
code
>
component, in an article element defined as the root of the component
</
div
>
</
article
>;
export
default
First
;
This diff is collapsed.
Click to expand it.
src/components/second.jsx
0 → 100644
+
16
−
0
View file @
0cf799f5
// import some other component
import
First
from
'
./first.jsx
'
;
/* define a stateless React component
* It uses another defined component, here First.
*/
const
Second
=
()
=>
<
div
>
<
h3
>
Second React component that uses another React component
</
h3
>
<
p
>
below comes a
<
code
>
First
</
code
>
component :
</
p
>
<
First
/>
</
div
>
export
default
Second
;
This diff is collapsed.
Click to expand it.
src/scripts/main.js
+
6
−
10
View file @
0cf799f5
import
React
from
'
react
'
;
import
{
createRoot
}
from
'
react-dom/client
'
;
const
bootstrapReact
=
()
=>
{
const
root
=
createRoot
(
document
.
getElementById
(
'
insertReactHere
'
));
// DOM existing parent for created element = "insertion point"
// import component
import
Second
from
'
../components/second.jsx
'
;
const
article
=
<
article
>
<
h3
>
Elements
created
by
React
,
using
jsx
<
/h3
>
<
div
>
this
div
,
created
by
React
,
is
in
an
article
<
/div
>
<
div
>
this
div
,
created
by
React
,
is
in
the
same
article
<
/div
>
<
/article>
;
const
bootstrapReact
=
()
=>
{
const
root
=
createRoot
(
document
.
getElementById
(
'
insertReactHere
'
));
// parent for created element = "insertion point"
root
.
render
(
article
);
}
root
.
render
(
<
Second
/>
);
// use defined imported component
}
window
.
addEventListener
(
'
DOMContentLoaded
'
,
bootstrapReact
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment