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
{"lastUpload":"2021-08-08T15:43:56.511Z","extensionVersion":"v3.4.3"} |
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
function ComponentExample({ defaultArray }) { | |
const [items, dispatchItems] = useReducer(itemReducer, | |
{ | |
array: [], | |
index: 0, | |
defaultArrayLength: 0 | |
}); |
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
function ComponentExample({ defaultArray }) { | |
const [array, setArray] = useState([]); | |
const [arrayIndex, setArrayIndex] = useState(0); | |
const [arrayLength, setArrayLength] = useState(0); | |
useEffect(() => { | |
array.splice(0, arrayLength); | |
setArrayIndex(0); | |
setArray([...defaultArray, ...array]); |
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
function ComponentExample({ defaultArray }) { | |
const [array, setArray] = useState([]); | |
const [arrayIndex, setArrayIndex] = useState(0); | |
useEffect(() => { | |
setArrayIndex(0); | |
setArray(defaultArray); | |
}, [defaultArray]); |
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
function ComponentExample({ defaultArray }) | |
const [array, setArray] = useState([defaultArray]); |
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
function ComponentExample() { | |
const [array, setArray] = useState(["a"]); | |
const [arrayIndex, setArrayIndex] = useState(0); | |
const changeItem = useCallback((indexIncrease) => { | |
const newIndex = arrayIndex + indexIncrease; | |
if (newIndex >= array.length || newIndex < 0) return; | |
setArrayIndex(newIndex); | |
}, [arrayIndex, array]); |
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
export default function Example() { | |
const [someState, dispatchState] = useReducer(stateReducer, initialState); | |
return ( | |
<div> | |
<button className="button" | |
onClick={() => dispatchState({ | |
type: UPDATE_SOME_DATA, | |
payload: "newdata" |
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
function ContainerComponent({ someProp, children }) { | |
const withProps = React.Children.map(children, child => React.cloneElement(child, { someProp })); | |
return <>{withProps}</>; | |
} | |
<ContainerComponent someProp={value}> | |
<ComponentA /> | |
<ComponentA /> | |
<ComponentA /> | |
<ComponentA /> |
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
<ComponentA someProp={value} /> | |
<ComponentA someProp={value} /> | |
<ComponentA someProp={value} /> | |
<ComponentA someProp={value} /> |