fix: http json value would changed

This commit is contained in:
Joel 2024-03-28 11:34:31 +08:00
parent de3fd0f382
commit 85b45a7cd0
2 changed files with 5 additions and 3 deletions

View File

@ -61,7 +61,7 @@ const EditBody: FC<Props> = ({
draft.data = value
})
onChange(newBody)
})
}, type === BodyType.json)
const isCurrentKeyValue = type === BodyType.formData || type === BodyType.xWwwFormUrlencoded

View File

@ -9,15 +9,17 @@ const strToKeyValueList = (value: string) => {
})
}
const useKeyValueList = (value: string, onChange: (value: string) => void) => {
const useKeyValueList = (value: string, onChange: (value: string) => void, noFilter?: boolean) => {
const [list, setList] = useState<KeyValue[]>(value ? strToKeyValueList(value) : [])
useEffect(() => {
if (noFilter)
return
const newValue = list.filter(item => item.key && item.value).map(item => `${item.key}:${item.value}`).join('\n')
if (newValue !== value)
onChange(newValue)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [list])
}, [list, noFilter])
const addItem = useCallback(() => {
setList(prev => [...prev, { key: '', value: '' }])
}, [])