All files / Form/withField index.js

100% Statements 8/8
100% Branches 2/2
100% Functions 3/3
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14          2x 4x 4x 4x 4x 4x 4x    
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} />
}