import React from "react"
import { Context, PathContext, joinPaths } from ".."
import _ from "lodash"
import { useContext, useCallback } from "react"
export default BaseComponent => props => {
const { data, set } = useContext(Context)
const path = useContext(PathContext)
const finalPath = joinPaths(path, props.path)
const value = finalPath ? _.get(data, finalPath) : data
const setValue = useCallback(val => set(finalPath, val), [finalPath])
return <BaseComponent setValue={setValue} value={value} {...props} />
}
|