events input ref

This commit is contained in:
Virginie Ky 2020-01-17 17:20:27 +01:00
parent 27786d1d1f
commit e444cf0119

View File

@ -1,4 +1,4 @@
import React, { useEffect } from 'react'; import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useGlobalContext } from 'strapi-helper-plugin'; import { useGlobalContext } from 'strapi-helper-plugin';
@ -12,10 +12,12 @@ const EventInput = ({
value: inputValue, value: inputValue,
}) => { }) => {
const { formatMessage } = useGlobalContext(); const { formatMessage } = useGlobalContext();
const onBlurRef = useRef();
onBlurRef.current = onBlur;
useEffect(() => { useEffect(() => {
onBlur({ target: { name, value: inputValue } }); onBlurRef.current();
}, [inputValue, onBlur]); }, [onBlurRef, inputValue]);
const headersName = [ const headersName = [
formatMessage({ id: `Settings.webhooks.events.create` }), formatMessage({ id: `Settings.webhooks.events.create` }),
@ -58,6 +60,7 @@ const EventInput = ({
onChange({ target: { name: inputName, value: Array.from(set) } }); onChange({ target: { name: inputName, value: Array.from(set) } });
}; };
console.log('yoyo');
return ( return (
<Wrapper> <Wrapper>
<table> <table>
@ -99,4 +102,4 @@ EventInput.propTypes = {
value: PropTypes.array, value: PropTypes.array,
}; };
export default EventInput; export default React.memo(EventInput);