2021년 목표설정

이미지
기본적으로 작년에 달성하지 못한 것들을 하려고 생각중인데..코로나가 언제까지 이어질지, 한국이나 북해도는 갈 수 있을지..자격증은 응시 가능할지..여러가지가 불확실하다. 2021년은 무엇보다 정신적인 부분과 경제적인 부분에 중점을 두고 조금 더 치열하게 지내보고 싶다. 일본나이로도 30대 마지막 해, 이제 불혹에 접어드는 나이..복잡하지만 심플하게. 육체적목표 : 트라이에슬론 스탠다드 도전하기 정신적 : 자격증2개 도전 + 자체개발 서비스 론칭 가족적 : 가정의 평화를 유지하기 경제적 : 외식과 유흥비를 줄이고 부수입을 늘려서 결과적으로 저축하기 사회적 : 목표세미나를 포함해서 민단과 개인인맥의 활성화와 교류를 촉진하기

[react-native] uuid 생성이 에러가 날 때 대처법 

ToDo 앱을 연습하는데 ID생성이 안되더라..
uuid 라는 패키지를 사용하면 된다던데 한참을 헤메었다.

우선, 맥에서는 Xcode가 설치되어 있지 않으면 안되니 필히 설치할 것.

다음, npm 으로 다음 명령어를 입력해서 uuid를 설치한다
> npm install --save uuid

그리고나서 필요한 페이지에 다음과 같이 임포트 하면 된다던데...
import { v1 as uuidv1 } from 'uuid';  
const ID = uuidv1();

안된다..에러난다..ㅠㅠ
Error : crypto.getRandomValues() not supported.

신나게 찾아보니 react-native-get-random-values 를 설치하라길래 했다.
> npm install --save react-native-get-random-values
설치 후 페이지에 임포트
import 'react-native-get-random-values';

그래도 에러가 난다...열심히 찾아봤는데 버전문제?? v1은 비추라고 다른 거 써봤는데 똑같다.
Error:TypeError: null is not an object (evaluating 'RNGetRandomValues.getRandomBase64')

콘솔에도 안찍히고..그냥 랜덤값이 생성이 안되더라..상수로 값 집어넣으면 멀쩡하게 움직임.

리엑트 네이티브에서 사용가능한 react-native-uuid 도 있다길래 해봤는데 안된다..ㅠㅠ
Error : undefined Unable to resolve module `buffer` from `node_modules/safe-buffer/index.js`: buffer could not be found within the project.

버퍼 지워보고 실행해도 똑같고...재설치를 해봐도 안되고...그러다가 참고 링크를 참조해서 해결했다.

방법은 null is not an object 를 해결하기 위해서、16 비트로 된 랜덤값을 ( 0 – 255 ) 생성해서 uuid 의 생성시드값으로 전달하는 것이다. 호오...난 역시 재능이 없나봐..ㅠㅠ

자바스크립트 파일을 하나 만들어서 uuidSeed.js 로 이름붙이고 다음과 같이 랜덤값 생성
// ./uuidSeed.js
export const seed = () => {
const one = Math.floor((Math.random() * 100) / 3.92);
const two = Math.floor((Math.random() * 100) / 3.92);
const three = Math.floor((Math.random() * 100) / 3.92);
const four = Math.floor((Math.random() * 100) / 3.92);
const five = Math.floor((Math.random() * 100) / 3.92);
const six = Math.floor((Math.random() * 100) / 3.92);
const seven = Math.floor((Math.random() * 100) / 3.92);
const eight = Math.floor((Math.random() * 100) / 3.92);
const nine = Math.floor((Math.random() * 100) / 3.92);
const ten = Math.floor((Math.random() * 100) / 3.92);
const eleven = Math.floor((Math.random() * 100) / 3.92);
const twelve = Math.floor((Math.random() * 100) / 3.92);
const thirteen = Math.floor((Math.random() * 100) / 3.92);
const fourteen = Math.floor((Math.random() * 100) / 3.92);
const fifteen = Math.floor((Math.random() * 100) / 3.92);
const sixteen = Math.floor((Math.random() * 100) / 3.92);
return [
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
ten,
eleven,
twelve,
thirteen,
fourteen,
fifteen,
sixteen
];
};
필요한 곳에서 임포트:
// seed 를 임포트。
import "react-native-get-random-values";
import { v1 as uuidv1 } from "uuid";
import { seed } from "./uuidSeed";
// 사용할 땐 요렇게。
var ID = uuidv4({ random: seed() })
uuidv4({ random: seed() }) 를 생성하면 요렇게 값이 나온다
0e0c1207-0f0b-4a17-9309-110c06141608
060a090b-0c03-4900-9506-010b0b010705
0814040d-0413-4805-8217-080d0e000804
09130c13-0d18-4b04-9104-111312020e14
[참고]
https://www.jacepark.com/how-to-use-uuid-in-react-native-with-expo/

댓글

이 블로그의 인기 게시물

[메모] PostgreSQL에서 Insert 하는 경우 자동채번 PK가 중복에러 나는 경우

[C# & LINQ] 랜덤으로 데이터를 한 개 추출하는 방법