import React, { useState } from "react";
const MemoID = ({ getID }) => {
return Array.from(new Array(getID)).map((_, i) => {
return <p key={i}> {i} </p>;
});
};
export default function App() {
let [getID, setID] = useState(0);
return (
<>
<MemoID key={getID} {...{ getID }} />
<button onClick={() => setID(getID + 1)}> clickMe </button>
</>
);
}
//css
.submit.myStyles1 {
}
.submit.myStyles2 {
}
.submit.myStyles3 {
}
const myfunction1 = () => {}
const myfunction2 = () => {}
const PhoneBTN = ({phone}) => (
<a className="phone" href={`tel:${phone}`}>
<img src="./Assets/Phone.svg" alt="" />
</a>
)
const Button = ({type,text}) => {
return (
type === "phone" ?
<PhoneBTN {...{phone:text}} onClick={myfunction1}/>:
<button className="submit myStyles" onClick={myfunction2}>{text}</button>
)
}
const render = () => (
<Button {...{type:"phone",text:""}}/>
)
//index.js
import React from "react";
import { render } from "react-dom";
// import react router
import { BrowserRouter, Link } from "react-router-dom";
import toLinkParams from "./toLinkParams";
const params = {
pathname: "/signup",
search: toLinkParams({
lang: "ua",
source: "3",
offer: 1,
country: "ua"
})
};
const App = () => (
<BrowserRouter>
<div className="sans-serif">
<Link to={params}>Button</Link>
</div>
</BrowserRouter>
);
render(<App />, document.getElementById("root"));
//toLinkParams.js
export default function toLinkParams(params) {
return (
"?" +
Object.entries(params)
.map((param) => {
const [key, value] = param;
return `${key}=${value}`;
})
.join("&")
);
}
import React, { useState } from "react";
export default function App() {
let [getID,setID] = useState(0);
return (
<>
<p> {getID} </p>
<button onClick={ () => setTimeout(() => setID(getID + 1),800)} > clickMe </button>
</>
)
}
import React, { useState } from "react";
const MemoID = ({getID}) => {
return Array.from(new Array(getID)).map( (_,i) => {
return (<p key={i}> {i} </p>)
})
}
export default function App() {
let [getID,setID] = useState(0);
return (
<>
<MemoID key={getID} {...{getID}}/>
<button onClick={ () => setTimeout(() => setID(getID + 1),800)} > clickMe </button>
</>
)
}