Skip to content

Instantly share code, notes, and snippets.

@netgfx
Created August 19, 2022 10:22
Show Gist options
  • Save netgfx/27cd1d882b2d827ce93cb91a3dacb7e8 to your computer and use it in GitHub Desktop.
Save netgfx/27cd1d882b2d827ce93cb91a3dacb7e8 to your computer and use it in GitHub Desktop.
Framer + Airtable calculate total
export function getTotal(Component): ComponentType {
return (props) => {
const [store, setStore] = globalStore()
useEffect(() => {
var total = 0
var selectedData = []
_.forEach(store.selectedProducts, (item) => {
var filteredArray = _.filter(
store.airtableData,
(product) => product.fields["Short Description"] == item
)
selectedData.push(filteredArray)
})
selectedData = _.flatten(selectedData)
for (var i = 0; i < selectedData.length; i++) {
total += selectedData[i]["fields"]["Total"]
}
setStore({ total: total })
}, [store.selectedProducts])
return <Component {...props} text={`\$${store.total}`} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment