Created
September 3, 2021 11:43
-
-
Save Steven24K/53cf38985313c880e27fc0c7feb889d2 to your computer and use it in GitHub Desktop.
A simple utility function to set the state of a custom block
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 setBlockState = <K extends keyof BLOCKPROPS>(prop: K, newValue: BLOCKPROPS[K]) => (s: CMSState<customBlockData, extra_images, PublicSite_CustomPageData>): CMSState<customBlockData, extra_images, PublicSite_CustomPageData> => { | |
if (!s.blocks.has(props.block_index)) return s | |
let current_block = s.blocks.get(props.block_index) as any | |
if (current_block.kind != 'BLOCK_NAME') return s | |
current_block = ({ | |
...current_block, | |
value: { | |
...current_block.value, | |
fst: { | |
...current_block.value.fst, | |
[prop]: newValue | |
}, | |
} | |
}) | |
return ({ ...s, blocks: s.blocks.set(props.block_index, current_block) }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment