[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to fetch appears. Please help. #541

Open
jungsikjeong opened this issue Feb 7, 2024 · 0 comments
Open

Failed to fetch appears. Please help. #541

jungsikjeong opened this issue Feb 7, 2024 · 0 comments

Comments

@jungsikjeong
Copy link
import React, { useState, useEffect } from 'react';
import NotionPage from './pages/NotionPage';

const App = () => {
  const [notionData, setNotionData] = useState(null);

  useEffect(() => {
    // Notion 페이지 정보를 가져오는 비동기 함수 또는 API 호출을 수행
    const fetchNotionData = async () => {
      const NOTION_API_URL = 'https://api.notion.com/v1';
      const PAGE_ID = process.env.REACT_APP_PAGE_ID;
      const NOTION_TOKEN = process.env.REACT_APP_SECRET;

      try {
        const response = await fetch(`${NOTION_API_URL}/blocks/${PAGE_ID}`, {
          headers: {
            Authorization: `Bearer ${NOTION_TOKEN}`,
            'Notion-Version': '2021-08-16',
          },
        });

        if (!response.ok) {
          throw new Error('Notion API 호출에 실패했습니다.');
        }

        const data = await response.json();
        setNotionData(data);
      } catch (error) {
        console.error('Error fetching Notion data:', error);
      }
    };

    fetchNotionData();
  }, []);

  return (
    <div className='App'>
      {notionData ? <NotionPage notionData={notionData} /> : '로딩 중...'}
    </div>
  );
};

export default App;

Is there something wrong with my code?
I only use React.
Could it be because of notion’s CORS? Is there a way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant