This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import db from 'db.server'; | |
import MyClientComponent from 'MyComponent.client'; | |
function MyServerComponent(props) { | |
const { id } = props; | |
const dataById = db.data.get(id); | |
return <MyClientComponent data={dataById} />; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MyClientComponent from 'MyComponent.client'; | |
function MyServerComponent(props) { | |
// For instance, the data could be fetched directly from a database | |
const { data } = props; | |
return <MyClientComponent data={data} />; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/g; | |
const str = 'test1test2'; | |
// Using spread operator | |
const array = [...str.matchAll(regex)]; | |
// Using `from` method | |
const array2 = Array.from(str.matchAll(regex)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/g; | |
const result = 'test1test2'.matchAll(regex); | |
const [matchingValue, matchingValue2] = result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/g; | |
const result = 'test1test2'.matchAll(regex); | |
for (const matchingValue of result) { | |
console.log(matchingValue); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/g; | |
let matchingValue; | |
while ((matchingValue = regex.exec('test1test2')) !== null) { | |
console.log(matchingValue); | |
} | |
// Output: | |
// ["test1", "e", "st1", "1", index: 0, input: "test1test2", groups: undefined] | |
// ["test2", "e", "st2", "2", index: 5, input: "test1test2", groups: undefined] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/g; | |
const result = 'test1test2'.matchAll(regex); | |
const resultAsArray = [...result]; | |
console.log(resultAsArray[0]); // ["test1", "e", "st1", "1", index: 0, input: "test1test2", groups: undefined] | |
console.log(resultAsArray[1]); // ["test2", "e", "st2", "2", index: 5, input: "test1test2", groups: undefined] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/g; | |
const result = 'test1test2'.matchAll(regex); | |
console.log(result); // [RegExpStringIterator] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regex = /t(e)(st(\d?))/; | |
const result = 'test1test2'.match(regex); | |
console.log(result); // ['test1', 'e', 'st1', '1', index: 0, input: "test1test2", groups: undefined] |