import React, { useContext, useRef } from 'react';
import { TokenContext } from '../../utilities/token-provider';
const NewsPublisher = props => {
//context
const authTokens = useContext(TokenContext);
//refs
const titleRef = useRef();
const authorRef = useRef();
const bodyRef = useRef();
return (
News Publisher
);
};
const handleSubmit = async (title, author, body, tokenFetch) => {
title = title.trim();
author = author.trim();
body = body.trim();
//fetch POST json data
const result = await tokenFetch(
`${process.env.NEWS_URI}/news`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
title,
author,
body
})
}
);
if (!result.ok) {
return [`${result.status}: ${await result.text()}`];
}
const json = await result.json();
return [null, json.index];
};
export default NewsPublisher;