#how does React work?
67 messages · Page 1 of 1 (latest)
yes ofc
import React, {Component} from "react";
import Typed from "react-typed";
export class test extends Component{
render() {
return(
<div className="animated-typing">
<Typed
strings={
[
"rtesrfesrfsetfwe",
"raeresarse",
]
}
typeSpeed={150}
backSpeed={100}
loop
/>
</div>
)
}
}```
this is in test.jsx
oh my... you are using classes in React?
import './App.css';
import React,{Component} from "react";
class App extends Component{
constructor(props) {
super(props);
}
render() {
return (
<div>
<test/>
</div>
);
}
}
export default App;
that's in app.js
yhea? why
i looked a bit on W3 and some other blogs
they said it was like this
Very few people use it. Most of them use functional components
at first i used functions but it didn t work
Can you show what you did when you used functions?
yhea that s what i did at first
ok lemme re write it
import React from "react";
import Typed from "react-typed";
function test() {
return(
<>
<div className="animated-typing">
<Typed
strings={
[
"rtesrfesrfsetfwe",
"raeresarse",
]
}
typeSpeed={150}
backSpeed={100}
loop
/>
</div>
</>
)
}```
import './App.css';
function App() {
return (
<div className="App">
<test/>
</div>
);
}
export default App```
Import test in app.js
but first export test
Add export default test in test.js
and import test from "[test.js path here]"
np
but
why does Test have to be in maj?
it doesn't work if it dont put a maj
and is there a way to importe every JSX files from the component folder?
maj?
You mean why it is "Test" instead of "test"?
yes
that's just how react works
lol ok
no real reason behind it
and can you do that?
or do i have to import every jsx file one by one?
hmm... I am not too sure
ok i'll try this thanks
Do you happen to know how can i pass a string in test.jsx and define the string in App.js
something like test(string sentence) {} in test.jsx
then test("hello world") in app.js
okk thanks
import Type from "./components/Type";
import './App.css';
function App() {
return (
<div className="App">
<Type/>
</div>
);
}
export default App;
import React from "react";
import Typed from "react-typed";
import './Type.css';
function Type() {
return(
<>
<div className="animated-typing">
<Typed
strings={
[
"Hey there! \n" +
"My name is Xyphes \n" +
"and this is my portfolio ;)",
]
}
typeSpeed={150}
backSpeed={100}
loop
/>
</div>
</>
)
}
export default Type
i'm trying to make new lines but \n doesnt work so i m just going to use <Type/> multiple times
Here, you would write <Type/> as <Type my_string = "[YOUR STRING]"/>
and this function Type() will become function Type({my_string})
then you can use my_string in your code
https://reactjs.org/docs/components-and-props.html Also, you should read the docs on props
I tried putting string= {str} but it didnt work
i also tried with just props
function Type({str}) {
return(
<>
<div className="animated-typing">
<Typed
strings={
{str}
}
typeSpeed={150}
backSpeed={100}
loop
/>
</div>
</>
)
}```
strings={
{str}
}
typeSpeed={150}
backSpeed={100}
loop
/>```
kk
i'll chaange that
it still does not work 😦
i tried to change it is some place but i can't understand haha
i also tried something like this ```js
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;
root.render(element);
and it seemed to work on codepen.io